Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have written a basic HTML page consisting of submit button , on button press a SOAP request will be send to my application URL. Below is the code i have written , i have face a 401-error.How can i over come this error???

i am unable to figure out the mistake ,request you to help me out. The same Soap body works when i try through SOA client

<html>
<head> 
    <title>SOAP JavaScript Client Test</title>
    <b>Creating a SOAP body by passing url and crdentials</b>
    <script type="text/javascript">
        function soap() {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'http:// URL?wsdl', true,'username','password');
            // build SOAP request
            var sr =  '<soapenv:Envelope'+
      'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' + 
      'xmlns:v1="http:// url/user/v1_1"' + 
      'xmlns:user="http:// url/user">' +
      'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
      'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
      '<soapenv:Header/>' +
      '<soapenv:Body >' +
      '<v1:LogInRequest>' +
       '<username xsi:type="xsd:string">username</username>' +
       '<password xsi:type="xsd:string">password</password>' +
      '</v1:LogInRequest>' +
      '</soapenv:Body>' +
      '</soapenv:Envelope>' 

            xmlhttp.onreadystatechange = function () {
              //alert("HI");
                if (xmlhttp.readyState == 4) {
                   // if (xmlhttp.status == 200) {

                        alert(xmlhttp.readyState);
                        alert(xmlhttp.status);
                    //}
                    //alert(xmlhttp.responseText);
                }
            }
            // Send the POST request
             xmlhttp.setRequestHeader('Content-Type', 'text/xml');
             xmlhttp.send(sr);


        }
    </script>
</head>
<body> //
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Soap" onclick="soap();" />
        </div>
    </form>
</body>
<html>
share|improve this question
    
Can you post the error? –  Hodaya Shalom Apr 2 '13 at 10:16
    
@hodaya shalom: The error i am able to see is as below: OPTIONS URL?wsdl 401 (Full authentication is required to access this resource) mySoap.html:37 soap mysoap.html:37 onclick mysoap.html:48 XMLHttpRequest cannot load qa1.vidyo.com/services/v1_1/VidyoPortalUserService?wsdl. Origin null is not allowed by Access-Control-Allow-Origin. mysoap.html:1 –  user2235526 Apr 2 '13 at 10:42
    
This seems like CORS issue. Browser issues a OPTIONS request for different domains to get the origin policy headers. See en.wikipedia.org/wiki/Cross-origin_resource_sharing –  LeZuse Apr 2 '13 at 10:50
    
but i dont get any error saying so,instead i get a error 401 and status == 0 . is there any thing wrong from my code point of view??? the same body is working through SOA tool.... –  user2235526 Apr 2 '13 at 11:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.