javascript
  • ajax
  • web-services
  • cors
  • 2016-05-13 25 views 0 likes 
    0

    即时通讯问题。 我明白了。CORS麻烦无法解决jquery,laravel5.2

    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">557956789</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">555</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">[email protected]</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寄存器:895个OPTIONS pagofacil.net/st/public/Wsstransaccion/ 500(内部服务错误) 2-寄存器:895的XMLHttpRequest不能加载pagofacil.net/st/public/Wsstransaccion/。对预检请求的响应不会通过访问控制检查:请求的资源上不存在“访问控制 - 允许来源”标头。因此不允许访问原产地'http://localhost:8000'。该响应的HTTP状态码为500. 3-register:895 Uncaught NetworkError:未能在'XMLHttpRequest'上执行'send':未能加载'pagofacil.net/st/public/Wsstransaccion/'。

    我已经试过REST,JSON邮政和我得到了与SOAP一样CORS麻烦。 我甚至试图禁用mozilla上的CORS安全选项,但没有工作(同样的错误)。

    我不是寻找一个解决方案在这里,但我不知道我在哪里可以看一下。 谢谢大家。

    更新16-05-2016 发现这个工具,并得到了一些有关此信息。 https://www.pagofacil.net/st/public/Wsrtransaccion/index/format/json?method=transaccion&data[nombre]=Juan&data[apellidos]=Lopez&data[numeroTarjeta]=557956789&data[cvt]=123&data[cp]=11560&data[mesExpiracion]=10&data[anyoExpiracion]=18&data[monto]=6&data[idSucursal]=60f961360ca187d533d5adba7d969d6334771370&data[idUsuario]=62ad6f592ecf2faa87ef2437ed85a4d175e73c58&data[idServicio]=3&data[email][email protected]&data[telefono]=5550220910&data[celular]=555&data[calleyNumero]=AnatoleFrance311&data[colonia]=Polanco&data[municipio]=Migueldalgo&data[estado]=DistritoFederal&data[pais]=Mexico

    简而言之,pagofacil.net服务器不允许CORS。

    回答

    0

    我想原因是服务器不允许OPTIONS请求,这表明他们不允许CORS。我在那里CORS启用了服务器和运行curl 'https://...myserver.../' -I -X OPTIONS -H 'Access-Control-Request-Method: POST' -H 'Origin: http://localhost:8000/' 返回以下标题:

    HTTP/1.1 200 OK 
    Content-Length: 0 
    Server: Microsoft-IIS/7.0 
    Access-Control-Allow-Origin: * 
    X-Powered-By: ASP.NET 
    Date: Sat, 14 May 2016 07:06:00 GMT 
    Set-Cookie: SERVERID=mon03; path=/ 
    Cache-control: private 
    

    这基本上说,“你可以做任何起源POST请求”。

    发行对您的服务器curl 'https://www.pagofacil.net/st/public/Wsstransaccion/' -I -X OPTIONS -H 'Access-Control-Request-Method: POST' -H 'Origin: http://localhost:8000/'

    一样卷曲命令返回

    HTTP/1.1 500 Internal Service Error 
    Date: Sat, 14 May 2016 07:06:09 GMT 
    Server: Apache/2.2.3 (Red Hat) 
    X-Powered-By: PHP/5.2.17 
    Content-Length: 269 
    X-XSS-Protection: 1; mode=block 
    X-Content-Type-Options: nosniff 
    Connection: close 
    Content-Type: text/xml; charset=utf-8 
    

    “内部服务错误”表示你不能做OPTIONS请求,因此,你不能做的CORS请求你正在努力去做。

    如果服务器不允许CORS,没有什么可以做,除了要求他们启用它,或者您的呼叫路由通过自己的代理服务器,在那里你能CORS。然后,该服务器可以向pagofacil发送请求并将数据返回给您。

    +0

    非常感谢您与其第三方公司进行验证。 –

    相关问题