通过 Web 服务在 React js 中进行 Soap 调用
我正在做一个反应应用程序,我需要接收来自网络服务的一些数据。我已经有了肥皂请求和响应的样本,并且我已经完成了邮递员的一些请求,并且工作正常。但是,当我想在 React 上发出肥皂请求和响应时,每次 CORS 阻止我访问 XMLHttpRequest 时,它都会给我带来同样的问题
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'https:/************/Geral.asmx?op=ObterLojasActivas', true);
// build SOAP request
var sr = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">' +
'<soap12:Body>' +
'<ObterLojasActivas xmlns="http://microsoft.com/webservices/" />' +
'</soap12:Body>' +
'</soap12:Envelope>;';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}
}
}
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
}
function Login() {
return (
<div class="container-fluid" style={{
backgroundImage: `url(franchising.jpg)`
}}>
<div className="login-content d-flex align-items-center" >
<form className="form-signin mx-auto" onSubmit={soap}>
<div className="text-center mb-4">
<h1 className="h3 mb-3 font-weight-normal text-black font-weight-bold">Login</h1>
</div>
<input placeholder="Username" name='email' id="inputEmail" class="form-control my-4" />
<input type="password" placeholder="Password" name='pass' id="inputPassword" class="form-control my-4" />
<center><button className="btn btn-lg btn-block btn-login mb-5">Entrar</button></center>
</form>
</div>
</div>
);
}
export default Login;
I am doing an application on react where i need to receive some data coming from webservice. I already have the sample of soap request and response, and i already had done some request by the postman and it is working fine. But when i want to make a soap request and response on react, it ives me the same problem every time that is CORS has blocked my access to XMLHttpRequest
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'https:/************/Geral.asmx?op=ObterLojasActivas', true);
// build SOAP request
var sr = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">' +
'<soap12:Body>' +
'<ObterLojasActivas xmlns="http://microsoft.com/webservices/" />' +
'</soap12:Body>' +
'</soap12:Envelope>;';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}
}
}
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
}
function Login() {
return (
<div class="container-fluid" style={{
backgroundImage: `url(franchising.jpg)`
}}>
<div className="login-content d-flex align-items-center" >
<form className="form-signin mx-auto" onSubmit={soap}>
<div className="text-center mb-4">
<h1 className="h3 mb-3 font-weight-normal text-black font-weight-bold">Login</h1>
</div>
<input placeholder="Username" name='email' id="inputEmail" class="form-control my-4" />
<input type="password" placeholder="Password" name='pass' id="inputPassword" class="form-control my-4" />
<center><button className="btn btn-lg btn-block btn-login mb-5">Entrar</button></center>
</form>
</div>
</div>
);
}
export default Login;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是您在标头请求中缺少所需的 CORS 权限,更多信息如下: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMissingAllowOrigin
只需添加此行并它应该工作正常:
I think the problem is you are missing the required CORS permission in your header request, more info here: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMissingAllowOrigin
Simply add this line and it should work fine: