angular - 如何以角度 5 发出 POST 请求
问题描述
这是以下请求
this.http.post('http://localhost:8989/anchor_web_api/resources', this.resourceMap).subscribe(res => console.log(res));
我想在标题中传递一些参数。
如何在上述发布请求中传递诸如授权或跨源访问控制之类的标头请求
解决方案
你可以这样做,
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); }
);
}
推荐阅读
- java - 如何在不使用 SQLiteOpenHelper 内容提供程序插入数据的情况下获取 URI?(安卓)
- mysql - 403 从公共/图像文件夹 laravel vuejs xampp 加载图像时禁止
- java - 当服务器在同一域和同一端口上时,一项任务中的 SSL 握手失败,而另一项任务中的 SSL 握手成功
- python - 训练模型时如何验证测试集?
- flutter - 在flutter中单击gridview后如何显示详细信息
- php - 如何将 HTML 界面(提交 SQL 语句)连接到 PHP 文件,然后将 PHP 连接到我的数据库?
- java - JAVA:无法在循环中返回响应
- c++ - 减号和加号对c ++中的字符串有什么作用
- python-3.x - 我在 pyhton 3.8 中安装 scipy 时出错
- python - 对这个“实验室”感到困惑