如何使用jQuery通过基本身份验证安全地使用Soap Web Service(.asmx)? [英] How to consume soap web service (.asmx) secure by basic authentication using jQuery?

查看:106
本文介绍了如何使用jQuery通过基本身份验证安全地使用Soap Web Service(.asmx)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调用(.asmx)soap Web服务,该服务需要使用jQuery(或任何可行的方法)进行基本身份验证.

I am trying to call a (.asmx) soap web service that require basic authentication using jQuery (or anything that would work).

以及如何将参数传递到(.asmx)soap Web服务

And how to pass parameters to the (.asmx) soap web service

我无法在Google上提出任何答案.有可能吗?

I've not been able to come up with any answers on Google. Is it possible?

推荐答案

好的,最后我能够解决此问题:)
我搜索的方向错误,正在寻找如何使用$ .Ajax打开通过基本身份验证保护的URL,在这里我应该使用XMLHttpRequest()从JavaScript中搜索使用的SOAP服务.
以下是我的问题的答案:

OK, Finally I was able to resolve this issue :)
I was searching in the wrong direction, I was looking how to open the URL secured by basic authentication using $.Ajax, where I should search for consuming SOAP service from JavaScript using XMLHttpRequest()
the following is the answer to my question:

var symbol = "MSFT"; 
var xmlhttp = new XMLHttpRequest();
//xmlhttp.open("POST", "http://www.webservicex.net/stockquote.asmx?op=GetQuote", true);
// if you use username and password to secure your URL
xmlhttp.open("POST", "http://www.webservicex.net/stockquote.asmx?op=GetQuote", true, 'username', 'password');
xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
        console.log(xmlhttp.responseText);
    }
}
xmlhttp.setRequestHeader("SOAPAction", "http://www.webserviceX.NET/GetQuote");
xmlhttp.setRequestHeader("Content-Type", "text/xml");
var xml = '<?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> ' +
          '<GetQuote xmlns="http://www.webserviceX.NET/"> ' +
          '<symbol>' + symbol + '</symbol> ' +
          '</GetQuote> ' +
          '</soap:Body> ' +
          '</soap:Envelope>';
xmlhttp.send(xml);

这篇关于如何使用jQuery通过基本身份验证安全地使用Soap Web Service(.asmx)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆