Python 如何在reactjs中设置头请求
我正在尝试设置Python 如何在reactjs中设置头请求,python,security,reactjs,Python,Security,Reactjs,我正在尝试设置访问控制允许Origin跳过以下错误: XMLHttpRequest cannot load http://www.test.dev:8090/glasses/import/log/qa/qa2/20170106?headers%5BAc…llow-Headers%5D=Origin%2C%20X-Requested-With%2C%20Content-Type%2C%20Accept. No 'Access-Control-Allow-Origin' header is pres
访问控制允许Origin
跳过以下错误:
XMLHttpRequest cannot load http://www.test.dev:8090/glasses/import/log/qa/qa2/20170106?headers%5BAc…llow-Headers%5D=Origin%2C%20X-Requested-With%2C%20Content-Type%2C%20Accept. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.test.dev:3000' is therefore not allowed access.
但是我没有得到想要的结果。客户端在reactjs中实现,并向python web应用程序发送get请求。这是我的密码:
class InfoBox extends Component {
constructor() {
super();
this.state = {items:[]};
}
componentDidMount() {
Request.get('http://www.test.dev:8090/glasses/import/log/qa/qa2/20170106', {
headers:{
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept"
}
})
.then((response) => {
this.setState({items:response});
});
}
render() {
const content = this.state.items.map(function(item) {return <div>{item}</div>});
return (
<div >{content}</div>
);
}
}
class信息框扩展组件{
构造函数(){
超级();
this.state={items:[]};
}
componentDidMount(){
请求。获取('http://www.test.dev:8090/glasses/import/log/qa/qa2/20170106', {
标题:{
“访问控制允许来源”:“*”,
“访问控制允许标头”:“来源,X请求,内容类型,接受”
}
})
。然后((响应)=>{
this.setState({items:response});
});
}
render(){
const content=this.state.items.map(函数(项){return{item});
返回(
{content}
);
}
}
CORS不是从客户端启用的,而是从服务器端启用的
在正常的http
请求中,浏览器将首先发送一个选项请求,以验证源是否具有访问资源的权限。服务器将使用Access Control Allow Origin
标题进行响应。如果在标题中定义了源,浏览器将发送相应的PUT、POST、GET、DELETE请求
您需要在python服务器中指定这些头文件
response谢谢,在我将CORS移到python之后它就可以工作了。现在,我觉得我的问题有多傻:D.我尝试在客户端的请求和响应中应用此更改,但从未在服务器端尝试过。没问题,几乎所有人都会这样:)