I am trying to verify if a content exists in SharePoint using SharePoint content urls in Java such as
http://sharepointportal/Lists/News/Attachments/11/mylink.pdf
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.
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;
}
But while invoking this URL from Java, i am getting HTTP 401 - Authentication Required Error.
I also do have username & 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?