I am making a get request through postman see image from 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();
}
}
The debugging of my code can be seen in the following screenshot: debugging postman request
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.
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/
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.
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.
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.