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"

ekad
  • 14,436
  • 26
  • 44
  • 46
Nick Gallimore
  • 1,222
  • 13
  • 31

1 Answers1

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.