相关疑难解决方法(0)

在Angular 6中添加http标头

任何人都可以告诉我这是否是在Angular 6中向http请求添加标头的正确方法?

当我通过SwaggerUI进行调用时,我可以看到标题应该是:

url -X GET --header 'Accept: application/json' --header 'zumo-api-version: 2.0.0' 'https://myurl/tables/stuff'
Run Code Online (Sandbox Code Playgroud)

所以我添加了以下内容:

let headers: HttpHeaders = new HttpHeaders();
headers = headers.append('HttpHeader1', 'Accept:application/json');
headers = headers.append('HttpHeader2', 'zumo-api-version:2.0.0');
Run Code Online (Sandbox Code Playgroud)

然后电话:

getStuff(){
    return this.http.get('https://myurl/tables/stuff', {headers})
  }
Run Code Online (Sandbox Code Playgroud)

没有失败,但没有任何回报,我知道应该有.

谢谢

UPDATE

刚刚注意到我的通话中的网址实际上是https而不是http,这会有什么不同吗?

getStuff(){
        return this.https.get('https://myurl/tables/stuff', {headers})
      }
Run Code Online (Sandbox Code Playgroud)

http http-headers visual-studio-code angular

12
推荐指数
2
解决办法
4万
查看次数

标签 统计

angular ×1

http ×1

http-headers ×1

visual-studio-code ×1