最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Duplicate parameters in Angular $http - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 8

If 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();
发布评论

评论列表(0)

  1. 暂无评论