Accessing secured webservices thows unauthorized 401 error code.
There is a webservice located at the following url ( Please bear in mind that I have no access to change them, I have to live with it)
http://localhost:8080/mywebservices/wsdl?targetURI=testread
But these webservices require authentication when accessed.
i.e when I open the url directly it asks me for username and password, and when I provide them, it let's me see the WSDL.
I know it is a soap webservice., and I am providing the soap request message, but how do I provide the credentials as part of the request.......Please advise me
The operation that I am accessing is "testRead". I have used SOAPUI to build the soap Message.
- <script>
- $(document).ready(function(){
-
- var soapMessage ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ecom="testeread/testRead">'
- + ' <soapenv:Header/> '
- + ' <soapenv:Body> '
- + ' <ecom:ws_hello> '
- + ' <ecom:cHello>Rahman</ecom:cHello> '
- + ' </ecom:ws_hello> '
- + ' </soapenv:Body> '
- + '</soapenv:Envelope>';
-
- $.ajax({
- url: ' http://localhost:8080/mywebservices/wsdl?targetURI=testread ',
- type: "POST",
- dataType: "xml",
- data: soapMessage,
- //username: "devws",
- //password: "wsdev",
- contentType: "text/xml; charset=utf-8",
- beforeSend: function(req){
- console.log(soapMessage);
- req.setRequestHeader('Authorization', auth);
- },
- success:function(data){
- console.log(data);
- },
- error: function(XMLHttpRequest, textStatus, errorThrown)
- {
- console.log('An Ajax error was thrown.');
- console.log(XMLHttpRequest.reponseText);
- console.log(textStatus);
- console.log(errorThrown);
- }
- })
- });
- </script>