Accessing secured webservices thows unauthorized 401 error code.

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.

  1. <script>
  2. $(document).ready(function(){ 

  3. var soapMessage ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ecom="testeread/testRead">'
  4.  + ' <soapenv:Header/> '
  5.  + ' <soapenv:Body> '
  6.  + ' <ecom:ws_hello> '
  7.  + ' <ecom:cHello>Rahman</ecom:cHello> '
  8.  + '  </ecom:ws_hello> '
  9.  + ' </soapenv:Body> '
  10. + '</soapenv:Envelope>';
  11.  
  12.  $.ajax({ 
  13. url: ' http://localhost:8080/mywebservices/wsdl?targetURI=testread ',
  14. type: "POST",
  15. dataType: "xml",
  16. data: soapMessage,
  17. //username: "devws",
  18. //password: "wsdev",
  19. contentType: "text/xml; charset=utf-8",
  20. beforeSend: function(req){
  21.    console.log(soapMessage);
  22. req.setRequestHeader('Authorization', auth);
  23. },
  24. success:function(data){
  25. console.log(data);
  26. },
  27. error: function(XMLHttpRequest, textStatus, errorThrown) 
  28. console.log('An Ajax error was thrown.');
  29.                 console.log(XMLHttpRequest.reponseText);
  30.                 console.log(textStatus);
  31.                 console.log(errorThrown);
  32. }
  33.  })
  34. });
  35. </script>