Reputation: 2810
I want to send a string parameter to my Web API Endpoint. The string is: TCmBqAKPGVMlTQ2Exw/viQ==
, so as we see it contains a /
. I am encoding this string and now the value is TCmBqAKPGVMlTQ2Exw%2FviQ%3D%3D
, but I still can not reach the API Endpoint.
This is the error I am getting:
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} message: "Http failure response for http://localhost:31676/api/TokenTest/check-token-validation/96/TCmBqAKPGVMlTQ2Exw%2FviQ%3D%3D:
404 Not Found" name: "HttpErrorResponse" ok: false status: 404 statusText: "Not Found" url: "http://localhost:31676/api/TokenTest/check-token-validation/96/TCmBqAKPGVMlTQ2Exw%2FviQ%3D%3D" proto: HttpResponseBase
Upvotes: 0
Views: 375
Reputation: 27588
If you are using Attribute routing , you can try below code sample :
[Route("api/[controller]")]
[ApiController]
public class TokenTestController : ControllerBase
{
[HttpGet]
[Route("check-token-validation/{id}")]
public ActionResult<IEnumerable<string>> CheckTokenValidation(int id, string para)
{
return new string[] { "value1", "value2" };
}
}
If the request is https://localhost:xxxx/api/TokenTest/check-token-validation/96?para=TCmBqAKPGVMlTQ2Exw/viQ==
you will get the correct result :
But url encode is always suggested .
Upvotes: 2
Reputation: 18973
You can use function encodeURIComponent(yourstring)
to encode special character in URL.
And change Url to http://localhost:31676/api/TokenTest/check-token-validation/96?parameterName=TCmBqAKPGVMlTQ2Exw%2FviQ%3D%3D
Upvotes: 1