title: Server returned HTTP response code: 401 for URL: https
body: <p>I'm using Java to access a HTTPS site which returns the display in an XML format. I pass the login credentials in the URL itself. Here is the code snippet:</p>
  
  <pre><code>DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();
  requestURL = "https://Administrator:Password@localhost:8443/abcd";
  
  try { 
      InputStream is = null;
      URL url = new URL(requestURL);
      InputStream xmlInputStream =new URL(requestURL).openConnection().getInputStream();
      byte[] testByteArr = new byte[xmlInputStream.available()];
      xmlInputStream.read(testByteArr);
      System.out.println(new String(testByteArr));
      Document doc = db.parse(xmlInputStream);
      System.out.println("DOC="+doc);
  } catch (MalformedURLException e) {
  } 
  </code></pre>
  
  <p>I'm creating a trust manager in the program which does not validate signed/unsigned certificates. But, on running the above program, I get the error 
  Server returned HTTP response code: 401 for URL: <a href="https://Administrator:Password@localhost:8443/abcd" rel="nofollow noreferrer">https://Administrator:Password@localhost:8443/abcd</a></p>
  
  <p>I can use the same url on my browser and it displays the xml correctly. Kindly let me know how to make this work within the Java program.</p>