【发布时间】:2016-09-10 02:20:15
【问题描述】:
我有麻烦了。 我明白了。
function soapRequest()
{
var soap_str='';
soap_str+='<?xml version="1.0" encoding="UTF-8"?>';
soap_str+='<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"';
soap_str+='xmlns:ns1="https://www.pagofacil.net/st/public/Wsstransaccion/?wsdl"';
soap_str+='xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"';
soap_str+='xmlns:xsd="http://www.w3.org/2001/XMLSchema"';
soap_str+='xmlns:ns2="http://xml.apache.org/xml-soap"';
soap_str+='xmlns:enc="http://www.w3.org/2003/05/soap-encoding">';
soap_str+='<env:Body>';
soap_str+=' <ns1:transaccion env:encodingStyle="http://www.w3.org/2003/05/soapencoding">';
soap_str+=' <param0 xsi:type="ns2:Map"><item><key xsi:type="xsd:string">nombre</key><value xsi:type="xsd:string">Juan A</value></item><item><key xsi:type="xsd:string">apellidos</key> <value xsi:type="xsd:string">Lopez Hernández</value></item> <item> <key xsi:type="xsd:string">numeroTarjeta</key> <value xsi:type="xsd:string">5579567890123456</value> </item> <item> <key xsi:type="xsd:string">cp</key> <value xsi:type="xsd:string">11560</value> </item> <item> <key xsi:type="xsd:string">cvt</key> <value xsi:type="xsd:string">123</value> </item> <item> <key xsi:type="xsd:string">monto</key> <value xsi:type="xsd:string">100</value> </item> <item> <key xsi:type="xsd:string">mesExpiracion</key> <value xsi:type="xsd:string">10</value> </item> <item> <key xsi:type="xsd:string">anyoExpiracion</key> <value xsi:type="xsd:string">15</value> </item> <item> <key xsi:type="xsd:string">idSucursal</key> <value xsi:type="xsd:int">1</value> </item> <item> <key xsi:type="xsd:string">idUsuario</key> <value xsi:type="xsd:int">1</value> </item> <item> <key xsi:type="xsd:string">idServicio</key> <value xsi:type="xsd:int">3</value> </item> <item> <key xsi:type="xsd:string">telefono</key> <value xsi:type="xsd:string">5550220910</value> </item> <item> <key xsi:type="xsd:string">celular</key> <value xsi:type="xsd:string">5550123456</value> </item> <item> <key xsi:type="xsd:string">calleyNumero</key> <value xsi:type="xsd:string">Anatole France 311</value> </item> <item> <key xsi:type="xsd:string">colonia</key> <value xsi:type="xsd:string">Polanco</value> </item> <item> <key xsi:type="xsd:string">municipio</key> <value xsi:type="xsd:string">Miguel Hidalgo</value> </item> <item> <key xsi:type="xsd:string">estado</key> <value xsi:type="xsd:string">Distrito Federal</value> </item> <item> <key xsi:type="xsd:string">pais</key> <value xsi:type="xsd:string">Mexico</value> </item> <item> <key xsi:type="xsd:string">email</key> <value xsi:type="xsd:string">comprador@correo.com</value> </item> <item> <key xsi:type="xsd:string">param1</key> <value xsi:type="xsd:string"/> </item> <item> <key xsi:type="xsd:string">param2</key> <value xsi:type="xsd:string">2</value> </item> <item> <key xsi:type="xsd:string">param3</key> <value xsi:type="xsd:string">3</value> </item> <item> <key xsi:type="xsd:string">param4</key> <value xsi:type="xsd:string"/> </item> <item> <key xsi:type="xsd:string">param5</key> <value xsi:type="xsd:string"/> </item> </param0> ';
soap_str+='</ns1:transaccion> </env:Body> </env:Envelope>';
var str=soap_str;
function createCORSRequest(method,url)
{
var xhr= new XMLHttpRequest();
if ("withCredentials" in xhr){
xhr.open(method,url,false);
}
else
{
//CORS not supported
console.log("CORS not supported");
alert("CORS not supported");
xhr=null;
}
return xhr;
}
var xhr= createCORSRequest("POST","https://www.pagofacil.net/st/public/Wsstransaccion/");
alert(xhr);
if(!xhr)
{
console.log("xhr issues");
return;
}
xhr.onload = function ()
{
var results = xhr.responseText;
console.log(results);
}
xhr.setRequestHeader('Content-Type','text/xml');
xhr.setRequestHeader("Access-Control-Allow-Origin","http://localhost:8000/");
alert(str);
xhr.send(str);
}
soapRequest();
我收到以下错误。 1-register:895 OPTIONS pagofacil.net/st/public/Wsstransaccion/500(内部服务错误) 2-register:895 XMLHttpRequest 无法加载 pagofacil.net/st/public/Wsstransaccion/。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'http://localhost:8000' 不允许访问。响应的 HTTP 状态代码为 500。 3-register:895 Uncaught NetworkError: 无法在“XMLHttpRequest”上执行“发送”:无法加载“pagofacil.net/st/public/Wsstransaccion/”。
我尝试过 REST、JSON Post,但我在使用 SOAP 时遇到了同样的 CORS 问题。 我什至尝试在 mozilla 上禁用 CORS 安全选项,但没有用(同样的错误)。
我不是在这里寻找解决方案,但我想知道我可以在哪里寻找。 谢谢大家。
简而言之,pagofacil.net 服务器不允许 CORS。
【问题讨论】:
标签: javascript ajax web-services cors