I don't know very well what is happening, but when I send a form with angular to the API that I have so that it enters it into the database if I put the '+' character in a string, it changes it to a space.
//Metodo para crear la vivienda
crearVivienda(vivienda : Vivienda): Promise<any>{
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({ headers: headers });
var body = "UR="+vivienda.UR+"&num_promocion="+vivienda.num_promocion+"&Direccion="+vivienda.direccion+";
console.log(body);
return this.http.post(viviendasURLcreate, body, options)
.toPromise()
.then()
.catch(this.handleError);
}
I have tried to send the form by postman and it enters it well. How would I have to make the request so that it does not exchange the character '+' for a space ' '
Thank you
This is usually a common problem and is usually very strange at first, since the
+
is used by the URL to separate two words. In order to use it as such, you must encode the values before adding them to the URL. In JS and TypeScript there isencodeURI()
This is how you use
encodeURI()
:In the same way you could decode it, if necessary.
Additional: