Web Services 对SOAP Web服务的JQuery AJAX 调用-访问被拒绝,正在SOAP UI中工作

yduiuuwa  于 2022-11-15  发布在  jQuery
关注(0)|答案(1)|浏览(192)

对SOAP Web服务的JQuery AJAX 调用抛出异常“拒绝访问”。请参见屏幕截图。它在SOAP UI中工作,因此SOAP请求似乎正确。请帮助查找问题并进行修复。
我的其他代码截图-http://tinypic.com/r/2liasgl/5

<!DOCTYPE html>
<html>
 <head>
    <title>Calling Web Service from jQuery</title>
    <script type="text/javascript" src="jquery-1.9.1.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            jQuery.support.cors = true;

            $("#btnCallWebService").click(function (event) {
                var wsUrl = "https://webservices..myservice.../";
                var soapRequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:dictionary:com.myservice.webservices"><soapenv:Header xmlns:wsse="http://myservice.org/wss/2004/01/myservice-1.0.xsd"><wsse:Security soapenv:mustUnderstand="1"><wsse:UsernameToken><wsse:Username>efhueeudedujed</wsse:Username><wsse:Password Type="http://myservice-wss-username-token-profile-1.0#PasswordText">dfdjfhdkjfa</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><urn:getETNInstances/></soapenv:Body></soapenv:Envelope>';

                $.ajax({
                    type: "POST",
                    url: wsUrl,
                    contentType: "text/xml",
                    dataType: "xml",
                    data: soapRequest,
                    success: processSuccess,
                    error: processError
                });

            });
        });

        function processSuccess(data, status, req) {
            if (status == "success")
                $("#response").text($(req.responseXML).find("HelloResult").text());
        }

        function processError(data, status, req) {
            alert(req.responseText + " " + status);
        }

    </script>
</head>
<body>
    <h3>
        Calling Web Services with jQuery/AJAX
    </h3>
    Enter your name:
    <input id="txtName" type="text" />
    <input id="btnCallWebService" value="Call web service" type="button" />
    <div id="response" />
</body>
</html>
46qrfjad

46qrfjad1#

可能的问题有:

  • 您使用的是绝对URL(使用https://serverdomain)。有些浏览器会封锁绝对URL,即使它们不是跨网域要求。如果您不是跨网域要求,请尝试改用相对URL(不使用https://serverdomain)。
  • 如果上面的方法不起作用,另一个可能的问题是你正在执行一个跨域请求。如果你需要执行跨域请求,你需要使用一些技巧,比如JSONPCORS

相关问题