【问题标题】:SOAP Prototype Ajax SOAPAction Header questionSOAP Prototype Ajax SOAPAction Header 问题
【发布时间】:2010-01-22 04:12:59
【问题描述】:

所以我试图发出一个请求并传入一个 SOAP 对象,问题是它返回正常(onSuccess)但 responseXML 不存在。我使用了 Fiddler 和 HTTP 客户端(OSX 版本的 fiddler)并输入了相同的请求,繁荣,都返回了正确的响应。有了原型,就没那么多了。

我在标题和参数字段中尝试过...

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript">
    function test(){
        var body = '<?xml version="1.0" encoding="utf-8"?>' +
        '<soap:Envelope' +
        ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
        ' xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"' +
        ' xmlns:tns="urn:uvindexalert" xmlns:types="urn:uvindexalert/encodedTypes"' +
        ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
        ' xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
        '  <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' +
        '    <tns:getUVIndexAlertByZipCode>' +
        '       <in0 xsi:type="xsd:string">92109</in0>' +
        '   </tns:getUVIndexAlertByZipCode>' +
        '  </soap:Body>' +
        '</soap:Envelope>';

        var headers = ["SOAPAction", " ", "Content-Type", "text/xml"];

        var request = new Ajax.Request("http://iaspub.epa.gov/uvindexalert/services/UVIndexAlertPort?wsdl", {
            contentType: "application/xml",
            requestHeaders: headers,
            parameters: "SOAPAction: ",
            postBody: body,
            onSuccess: function(response){
                var j = 0;
            },
            onFailure: function(){
                var i = 0;
            }
        });
    }

    test();
</script>

var i 和 j 只是为了让我知道它在哪里中断,以便我可以检查它。我也在网上查看并注意到有人说尝试而不是 text/xml application/xml 然后添加 charset=utf-8 所以我做了所有这些但仍然没有。任何人都知道如何使用 SOAPAction 取回 XML?

【问题讨论】:

    标签: javascript ajax soap prototypejs


    【解决方案1】:

    撇开跨站脚本安全问题不谈,我之前写过一个 Prototype.js SOAP 客户端,但在“Content-Type”和“SOAPAction”标头方面遇到了很多问题。我最终使用了以下方法并且它有效(但仅适用于同一域中的请求)。

    Content-Type: text/xml; charset=utf-8
    SOAPAction: ""
    

    网络服务器应为OPTIONS 请求发送此标头:

    Access-Control-Allow-Origin: *
    

    【讨论】:

      【解决方案2】:

      您不能使用 Ajax 进行跨域请求。这是一个安全限制。

      为了实现安全的跨域请求,正在进行多种不同的努力,但并非所有浏览器都支持它们,并且它们需要您尝试向其发出请求的站点的合作。许多人改为使用 HTTP 代理脚本 — 服务器上的一个脚本,用于接收 Ajax 请求、联系远程 URL 并传递响应。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-02
        • 1970-01-01
        • 2012-06-15
        • 2010-11-04
        相关资源
        最近更新 更多