pepaSoftware
pepaSoftware

Reputation: 35

Why does postman substitute characters in my get request string?

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

Answers (4)

Kalu
Kalu

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

MichaelMao
MichaelMao

Reputation: 2806

You need to encode the parameter on Postman. First add the parameter under Params tab

enter image description here

then select the value and right click the value chose EncodeURIComponent enter image description here

then you will get encoded parameter

enter image description here

Reference: https://learning.postman.com/docs/sending-requests/requests/

Upvotes: 1

Karl-Johan Sjögren
Karl-Johan Sjögren

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.

Picture of a non encoded url in postman

You can select the text and right click it to get the option to encode the value.

Picture of the context menu in Postman to encode values

This will encode the value properly and it will be received in your C# application as expected.

Picture of an encoded url in postman

Upvotes: 0

Ramin Quliyev
Ramin Quliyev

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

Related Questions