title: How to authenticate in sharepoint 2010 using username & password in Java?
body: <p>I am trying to verify if a content exists in SharePoint using SharePoint content urls in Java such as</p>
  
  <pre><code>http://sharepointportal/Lists/News/Attachments/11/mylink.pdf
  </code></pre>
  
  <p>Below is code for same. Here i am trying to get response code for a content URL by creating a HTTP connection from URL. If i get HTTP 200, it means content exists in SharePoint.</p>
  
  <pre><code>String fileUrl = "http://sharepointportal/Lists/News/Attachments/11/mylink.pdf";
  HttpURLConnection.setFollowRedirects(false);
  HttpURLConnection connection = (HttpURLConnection) new URL(fileUrl).openConnection();
  connection.setInstanceFollowRedirects(false);
  connection.setRequestMethod("HEAD");
  if(connection.getResponseCode() == HttpURLConnection.HTTP_OK)
  {
    fileExists = true;
  }
  </code></pre>
  
  <p>But while invoking this URL from Java, i am getting HTTP 401 - Authentication Required Error.</p>
  
  <p>I also do have username &amp; password for SharePoint with me. Is there any way i can use username/password details in URL to authenticate with SharePoint and chexk whether content exists?</p>