10

Given the following method in a controller for a ASP.NET Web API:

[HttpGet]
[ApiRoute("resource/{id}/end-point)]
public IHttpActionResult MethodName (int id, string clientTimeZone)
{
     ...
}

Whenever I submit a GET request to http://localhost:5684/api/v1/resource/1/end-point?client_timezone=%2B0500 clientTimezone is passed in to clientTimeZone as %2B0500 and it parses the encoded '+' sign into a space character. Why can't ASP.NET decode +'s from the URI?

In the header I have "ContentType = application/json" and a bearer token

I am trying to get "+0500" into my method but it is turning into " 0500"

2
  • Are you sure %2B is being sent and not +? Commented Apr 13, 2018 at 15:34
  • Yes %2B is being sent in, not + Commented Apr 13, 2018 at 17:56

1 Answer 1

3

Are you using Content-Type of application/x-www-form-urlencoded when consuming the api? This will treat a '+' character as a space when used in your URL.

More details here: When to encode space to plus (+) or %20?

Try changing your Content-Type to application/json instead and see if parameter binding behaves as expected.

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

1 Comment

I went ahead and tried changing the content type, that didn't work

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.