JB-*_*JB- 6 security http-headers response-headers reactjs
我有一个反应 js 应用程序。我想在从应用程序返回的每个响应中添加一些 http 标头。您能否建议如何实现这一点!
注意:我不想在请求中调用任何带有标头的 api。我希望我的反应应用程序在响应中使用一些自定义标头进行响应
小智 -4
const header = new Headers();
header.append('Access-Control-Allow-Origin', '*');
const body = {
author: author,
text: text
}
axios.post("https://api.test/posts/create", body, header)
.then((res) => {
this.setState({
result: res
});
})
.catch((error) => {
this.setState({
error: error.message
});
})
Run Code Online (Sandbox Code Playgroud)
您必须使用本机对象 Headers,并将其添加到 axios 中。
| 归档时间: |
|
| 查看次数: |
16637 次 |
| 最近记录: |