首页 > 解决方案 > 如何以角度 5 发出 POST 请求

问题描述

这是以下请求

this.http.post('http://localhost:8989/anchor_web_api/resources', this.resourceMap).subscribe(res => console.log(res));

我想在标题中传递一些参数。

如何在上述发布请求中传递诸如授权或跨源访问控制之类的标头请求

标签: angularangular5angular6

解决方案


你可以这样做,

    var headers = new Headers();
    this.createAuthorizationHeader(headers);
    headers.append('Content-Type', 'application/json');
     return this.http.post(
      'http://localhost:8989/anchor_web_api/resources', this.resourceMap, {
        headers: headers
      }).map(res => res)).subscribe(
        data => { console.log(data); },
        err => { console.log(err); }
      );
 }

推荐阅读