I want to add multiple parameters with the same name to a request URL. I'm using Angular's $http
.
The URL should look like this:
http://myBaseUrl?name1=value1&name1=value2...
I know that it is possible to make something like this when I set the values as an array:
http://myBaseUrl?name1=value1,value2...
But it has to be like the first one.
I want to add multiple parameters with the same name to a request URL. I'm using Angular's $http
.
The URL should look like this:
http://myBaseUrl?name1=value1&name1=value2...
I know that it is possible to make something like this when I set the values as an array:
http://myBaseUrl?name1=value1,value2...
But it has to be like the first one.
Share Improve this question edited Jul 18, 2022 at 14:00 Edric 26.9k13 gold badges87 silver badges95 bronze badges asked Oct 12, 2017 at 13:49 chocolate cakechocolate cake 2,4998 gold badges29 silver badges58 bronze badges 2- why do you need to add same key twice? GET HTTP request uses key=value structure – Maxim Shoustin Commented Oct 12, 2017 at 13:54
- 3 I know that it is not pretty. But the api expects the values this way. – chocolate cake Commented Oct 12, 2017 at 13:59
1 Answer
Reset to default 8If you're using HttpClient
you can use HttpParams
for this.
let params = new HttpParams();
// Assign parameters
params = params.append('firstParameter', 'valueOne');
params = params.append('firstParameter', 'valueTwo');
// Get request
this.http.get(`http://example.`, { params }).subscribe();