Javascript 来自Firefox扩展的SSL上的XMLHttpRequest
我将开发一个firefox扩展,它将XMLHttpRequest转换为WebService 我可以使用以下代码(来自overlay.js)正确查询服务:Javascript 来自Firefox扩展的SSL上的XMLHttpRequest,javascript,firefox,ssl,xmlhttprequest,Javascript,Firefox,Ssl,Xmlhttprequest,我将开发一个firefox扩展,它将XMLHttpRequest转换为WebService 我可以使用以下代码(来自overlay.js)正确查询服务: var req=“18481”; var xmlhttpreq=Components.classes[“@mozilla.org/xmlextas/xmlhttprequest;1”].createInstance(Components.interfaces.nsIXMLHttpRequest); xmlhttpreq.open(“POST”h
var req=“18481”;
var xmlhttpreq=Components.classes[“@mozilla.org/xmlextas/xmlhttprequest;1”].createInstance(Components.interfaces.nsIXMLHttpRequest);
xmlhttpreq.open(“POST”https://www.whereisnow.com/webservice“,假);//false=异步
xmlhttpreq.channel.loadFlags |=Components.interfaces.nsRequest.LOAD_BYPASS_缓存;
xmlhttpreq.send(请求);
如果(xmlhttpreq.readyState==4){
if(xmlhttpreq.status==200)
警报(xmlhttpreq.responseText);
其他的
警报(“错误:xmlhttpreq.status=“+xmlhttpreq.status”)
}
其他的
警报(“未准备就绪:xmlHttpreq.readyState=“+xmlHttpreq.readyState”);
responseText将是一个有效的xml,我可以对其进行操作,但是可以通过http和https(SSL)访问,我必须通过https进行访问,因为执行某些操作需要身份验证
为了通过https进行访问,我必须使用https://而不是http://修改端点,并以以下方式修改请求xml:
var req = "<soapenv:Envelope xmlns:dat=\"http://webservice.whereisnow.com/datatypes\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header><wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><wsse:UsernameToken wsu:Id=\"UsernameToken-1\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"><wsse:Username>MY_USERNAME</wsse:Username><wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">SHA1_OF_MY_PASSWORD</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><dat:CurrentDocument><dat:applicationId>1</dat:applicationId><dat:publisherId>84</dat:publisherId><dat:documentId>10</dat:documentId><dat:versionId>1</dat:versionId></dat:CurrentDocument></soapenv:Body></soapenv:Envelope>";
var req=“MY_USERNAMESHA1_OF_MY_PASSWORD184101”;
问题是服务器状态始终为500,而响应文本始终为:
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>InvalidSecurity</faultstring><detail></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
soapenv:ServerInvalidSecurity
有什么帮助吗
编辑
通过在中找到的代码,我发现服务的SSL证书工作正常。所以我认为问题不在于https…解决了,在open(…)之后添加以下行:
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>InvalidSecurity</faultstring><detail></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
xmlhttpreq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttpreq.setRequestHeader("SOAPAction", "whereIsNow");