0

我正在使用 Jquery 创建肥皂请求。以下是肥皂请求所需的信封。

POST /netforumaiatest2/xweb/secure/netforumxml.asmx HTTP/1.1
Host: amstest.aia.org
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.avectra.com/2005/Authenticate"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Authenticate xmlns="http://www.avectra.com/2005/">
      <userName>string</userName>
      <password>string</password>
    </Authenticate>
  </soap:Body>
</soap:Envelope>

我用jquery写了代码

var soapMessage='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Authenticate xmlns="http://www.avectra.com/2005/"><userName>user</userName><password>pass</password></Authenticate></soap:Body></soap:Envelope>';

    $.ajax({
    url: productServiceUrl,
    type: "POST",
    dataType: "xml",
    data: soapMessage,
    complete: endSaveProduct,
    contentType: "text/xml; charset=\"utf-8\""
           });

但在 endSaveProduct 中,我得到了status = error. 我怎样才能看到我发送的数据$.ajax call。请帮我。

4

4 回答 4

1

您可以使用beforeSend选项和控制台记录数据: beforeSend: function(data) {console.log(data);}

于 2012-07-19T09:39:46.160 回答
1

我会建议你以另一种方式做到这一点。对 PHP 文件(或 aspx)进行 ajax 调用并在那里进行 SOAP 调用。与 javascript 相比,您可以在这些语言中使用 soap 做更多的事情。

如果您决定使用 PHP,我不久前发现了这个可爱的类覆盖:

class SoapClientDebug extends SoapClient {
    public function __doRequest($request, $location, $action, $version) {
        print_r($request);
        return parent::__doRequest($request, $location, $action, $version);
    }
}

只需更改:

$client = new SoapClient('foo.wsdl');

$client = new SoapClientDebug('foo.wsdl');
于 2012-07-19T09:40:37.017 回答
0

使用Fiddler检查您的请求和响应。

于 2012-07-19T09:40:15.543 回答
0

在这里,我需要什么。我想打印在此处完成的 HTTPRequest 响应。

function endSaveProduct(xmlHttpRequest, status)
            {
              $(xmlHttpRequest.responseXML)
                {
                    alert(xmlHttpRequest.responseText);

通过在soap请求标头中添加操作来解决错误

$.ajax({
                       url: productServiceUrl,
                       type: "POST",
                       beforeSend: function (xhr){
                       xhr.setRequestHeader("SOAPAction", "URL/Authenticate");
                       //alert("in before send");
                       },
                       dataType: "xml",
                       data: soapMessage,
                       complete: endSaveProduct,
                       contentType: "text/xml; charset=\"utf-8\""
                       }).done(function () {alert("calling Authenticate");})
                .fail( function() {alert("fail");});
于 2012-07-20T05:50:23.497 回答