Reputation: 11
I don't understant why, and I don't find the answer anywhere.
I have this issue when i want use params in http request.
identificationClientMAil(phone: string, mail: string) : Observable <any>{
let params = new HttpParams().append('phone', phone).append('mail', mail);
return this.http.get('http://localhost:8000/Programme/extranet-api/public', { headers: this.headers, params: params })
.map(res => res.json())
.catch(err => {
throw 'error in source. Details: ' + err;
});
}
And my url look like this after:
Where is my problem ?
Upvotes: 1
Views: 194
Reputation: 1222
What kind of issue do you have? It can also be a server issue (incorrect path to resource or other). Anyway Dhyey had a good suggestion using URLSearchParams, though it is a better idea to let http.get handle the params conversion (as you had in your code) like:
return this.http.get('http://localhost:8000/Programme/extranet-api/public',
{ headers: this.headers, search: myUrlSearchParams })...;
Upvotes: 1
Reputation: 4335
You need to use URLSearchParams
:
let params = new URLSearchParams();
urlSearchParams.append('phone', phone);
urlSearchParams.append('mail', mail);
return this.http.get('http://localhost:8000/Programme/extranet-api/public?' + urlSearchParams.toString(), { headers: this.headers })
.map(res => res.json());
.catch(err => {
throw 'error in source. Details: ' + err;
});
Upvotes: 1