0
我有一個Perl腳本,調用WebService的WSDL,我嘗試將它移植到JavaScript中,沒有任何成功:( 我還需要爲了得到我的反應來驗證服務器。PhoneGap的通話WSDL
我需要使用這部分代碼在我的電話峽項目有任何建議,歡迎
perl腳本的樣子:。
my $url = "https://$user:$pass\@pathToMyExternalWSDL.xml?VERSION=1.1&STYLE=style";
my $soap = SOAP::Lite->service($url)->autotype(1)->readable(1)->on_fault(sub
{
my $soap = shift;
my $res = shift;
if(ref($res) eq '')
{
warn ($res);
}
else
{
warn($res->faultstring);
}
return new SOAP::SOM;
});
sub SOAP::Transport::HTTP::Client::get_basic_credentials{return $user=>$pass;}
my $response = $soap->action($param1, $param2);
請求看起來像:
Accept: text/xml
Accept: multipart/ *
Accept: application/soap
Content-Length: 926
Content-Type: text/xml; charset=utf-8
SOAPAction: "action"
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
...
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<action>
<param1 xsi:type="data_type1">myParam1</param1>
<param2 xsi:type="data_type2">myParam2</param2>
</wc:action>
</soap:Body>
</soap:Envelope>
我試圖從JavaScript和這個鱈魚同樣的反應:
<script type="text/javascript">
function soap() {
try {
var xmlhttp = new XMLHttpRequest();
var action = "action"; // same action like the script
var sURL= "https://user:[email protected]?VERSION=1.1&STYLE=style"; //same url like the script
xmlhttp.open("POST", sURL, false);
xmlhttp.setRequestHeader("Accept", "text/xml");
xmlhttp.setRequestHeader("Accept", "application/soap");
xmlhttp.setRequestHeader("Accept", "multipart/*");
xmlhttp.setRequestHeader("Content-Length", "926");
xmlhttp.setRequestHeader("SOAPAction", action);
xmlhttp.setRequestHeader("Content-Type", "text/xml");
xmlhttp.setRequestHeader("Content-Type", "charset=utf-8");
var SOAPEnvelope = "<?xml version='1.0' encoding='UTF-8'?> ";
SOAPEnvelope += "<soap:Envelope xmlns:mime='http://schemas.xmlsoap.org/wsdl/mime/' ";
SOAPEnvelope += "soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' ";
SOAPEnvelope += "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' ";
SOAPEnvelope += "xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' ";
...
SOAPEnvelope += "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ";
SOAPEnvelope += "xmlns:xsd='http://www.w3.org/2001/XMLSchema'>";
SOAPEnvelope += "<soapenv:Header/>";
SOAPEnvelope += "<soapenv:Body>";
SOAPEnvelope += "<wc:action>";
SOAPEnvelope += "<param1 xsi:type="data_type1">myParam1</param1>";
SOAPEnvelope += "<param2 xsi:type="data_type2">myParam2</param2>";
SOAPEnvelope += "</wc:action>";
SOAPEnvelope += "</soapenv:Body>";
SOAPEnvelope += "</soapenv:Envelope>";
xmlhttp.send(SOAPEnvelope);
}
catch (e) {
console.log(e);
}
//var tmpXML = xmlhttp.responseXML.xml
}
</script>
當我調用JavaScript函數我從螢火蟲這樣的響應:
> [Exception... "Access to restricted URI denied" code: "1012" nsresult:
> "0x805303f4 (NS_ERROR_DOM_BAD_URI)" ... { constructor={...}, code=1012, INDEX_SIZE_ERR=1, more...}
問候