2

I'm not receiving the expected Response Content on the client when the resource returns BadRequest.

[HttpGet]
[Route("Test", Name = "Test")]
public async Task<IHttpActionResult> Test()
{
    var result = BadRequest("test");
    return result;
}

On client (see hurl.it example below) I simply receive the string Bad Request in the body: Bad Request string in content

The response on the server seems to be fine: Response server side

It was working fine at some point (returning strings or ModelState in content) and recently we noticed this problem. I can't think of any recent change on server that could cause it.

It works neither locally nor when deployed on server.

It can be reproduced in any ApiController in the project.

return Ok("test"); works as expected.

Does anyone know what can cause this behavior?

Thank you!

6
  • Are you receiving correct json/xml formatted response? What happens if you get a valid request? How does that turn out? Please confirm, you are really intent to make Authorized requests? Commented Jul 15, 2015 at 22:22
  • This is exactly the problem I tried to describe: instead of expected content, in any format (in the example I gave - string test), I receive the string Bad Request. Regarding receiving 200 OK, as described, I can see the expected content (the string test). Commented Jul 16, 2015 at 12:10
  • Well you sir, got a very nice bug that should be fixed :), A few options you have is: Try with a blank project, see if that works. If that works then you know it's about your project and not about your local IIS or server (highly unlikely but still give it a shot..) Try different headers (application/json), without authentication. Thats all I got, good luck. Commented Jul 16, 2015 at 16:41
  • When I create a new project, everything works as expected. Played with different content-types - no luck. Authentication headers change nothing :( Commented Jul 16, 2015 at 19:01
  • 1
    Well we narrowed it down to your project, check your App_Start (Bundle,Route,Filter,WebApi) and Global.aspx for any weird differences (filters?) Perhaps your web.config contains custom errors? Try on POST,PUT,DELETE request, same? -> Must be config settings or different versions of assemblies. How about other 400 or 500 error responses? Remove Route? Running low on fuel here :) Commented Jul 16, 2015 at 21:03

1 Answer 1

1

It is hard to tell what goes wrong.

Things you could check:

  • Perhaps is your error caused by invalid authentication request
  • Try with a new project, if that makes difference then you know it's your project and there are no errors caused by your local IIS and server settings (highly unlikely but you never know.
  • Check your App_Start folder, containing the BundleConfig, RouteConfig, FilterConfig,WebApiConfig`. Perhaps some custom settings did cause to give you bad request error while it might be a not found error.
  • Check if it's only on Get request or also on others, could be caused by different versions of assemblies.
  • Check if you only have the problem with 400, or does 401, 500 gives the same problem?
  • Check your Web.Config file, these might contain <CustomErrors> that might redirect, or throw there own errors.

After some comments, custom erros seemed to be the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.