In an Angular Service I'm using HttpParams to send a string to the service:
get(phone: string): Observable<PhoneSearchResponse> {
let params = new HttpParams();
params = params.append("phone", phone); // sending "+123456"
return this._http.get<PhoneSearchResponse>(`${this._apiurl}/Get`, { params: params });
}
When calling get() with +123456
as parameter I'll get 123456
in the receiving service. So somewhere on the way the +
gets converted to a space.
Do I need to escape HttpParams to get them unchanged to the service?
If it matters, the backend is an asp.net core project. The called code in the controller:
[HttpGet("[action]")]
public async Task<JsonResult> Get(string phone) // receiving " 123456"
{
return Json(await PhoneSearchLogic.GetAsync(phone));
}
[Update] Very good explanation by Noémi Salaün - but I wonder if changing the parameters is expecteded behaviour "by design"? Or is the problem the ASP.NET Core controller, which should not unescape the + sign (and others)?