Reputation: 35
I am making a get request through postman and when the request reaches my controller, the characters like "+" are converted to empty spaces " ". The api is written in c#.
My controller code is:
[RoutePrefix("")]
public partial class _DesifrarCusController : CaramlController, I_DesifrarCusController
{
[HttpGet]
[Route("descifrarCus")]
public IHttpActionResult GetDescifrarCusResponse( [FromUri] string cus = null ) {
return Ok (ExecGetDescifrarCusResponse(cus));
//return Ok();
}
}
Does anyone have any idea what postman is doing with the request string?
I have tried to send the string between quotes and with ascii characters and still the problem persists.
I add capture of the postman headers
Upvotes: 1
Views: 2558
Reputation: 66
As people mentioned in other answers, it's encoding issue. Alternatively you could use [FromBody] and then just put your string in body request part of postman
public IHttpActionResult GetDescifrarCusResponse( [FromBody] string cus = null ) {
return Ok (ExecGetDescifrarCusResponse(cus));
//return Ok();
}
Upvotes: 0
Reputation: 2806
You need to encode the parameter on Postman. First add the parameter under Params
tab
then select the value and right click the value chose EncodeURIComponent
then you will get encoded parameter
Reference: https://learning.postman.com/docs/sending-requests/requests/
Upvotes: 1
Reputation: 17622
Data in URIs need to be UrlEncoded. When your C# application recevies the data it will decode it which will replace the plus signs with spaces (which to be fair is the older standard).
Postman won't do this automaticly for you, but it can help.
If you have a value like this.
You can select the text and right click it to get the option to encode the value.
This will encode the value properly and it will be received in your C# application as expected.
Upvotes: 0
Reputation: 380
Postman send data from query by encoding it with urlencode.This is normal. Sending this kind of long data from url is not best practise.I recommend use HttpPost and send data from body.
Upvotes: 0