如何使用username& amp ;;在sharepoint 2010中进行身份验证Java中的密码?

时间:2014-07-28 16:42:26

标签: java authentication sharepoint-2010

我正在尝试使用Java中的SharePoint内容网址验证SharePoint中是否存在内容,例如

http://sharepointportal/Lists/News/Attachments/11/mylink.pdf

下面是相同的代码。在这里,我试图通过从URL创建HTTP连接来获取内容URL的响应代码。如果我获得HTTP 200,则表示内容存在于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;
}

但是从Java调用此URL时,我收到HTTP 401 - 需要验证错误。

我也有用户名&与我一起使用SharePoint的密码。有没有什么办法可以使用URL中的用户名/密码详细信息来验证SharePoint和chexk是否存在内容?

1 个答案:

答案 0 :(得分:0)

我使用带有NTLM凭证的HTTPClient API工作。

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGetRequest = new  HttpGet(fileUrl);
org.apache.http.auth.Credentials credentials = new org.apache.http.auth.NTCredentials(username,password, workstation, domain);
httpClient.getCredentialsProvider().setCredentials(SharePoint_URL, SharePoint_Port),credentials);
HttpResponse response = httpClient.execute(httpGetRequest);
StatusLine status = response.getStatusLine();