1

我正在尝试从 j2ee 应用程序访问 MS Project Server 2013 的 REST api,它是 Microsoft Project Online 的一部分。网址是https://myCompany.sharepoint.com/sites/pwa/_api/ProjectServer/Projects

我使用以下代码:

String url = https://myCompany.sharepoint.com/sites/pwa/_api/ProjectServer/Projects
String username = "";
String pass = "";

try {
   Client client = Client.create();
   client.addFilter(new HTTPBasicAuthFilter(username, pass));
   WebResource webResource = client.resource(url);
   ClientResponse response = (ClientResponse)webResource.type(MediaType.APPLICATION_ATOM_XML).get(ClientResponse.class);
   InputStream inputStream = response.getEntityInputStream();
   String output = IOUtils.toString(inputStream);
   System.out.println("answer: " + output);
} catch (Exception e) {
   e.printStackTrace();
}

我收到的响应类型是 403。

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <m:code>-2147024891, System.UnauthorizedAccessException</m:code>
  <m:message xml:lang="en-US">Access denied. You do not have permission to perform this action or access this resource.</m:message>
</m:error>

我猜这与https有关,所以我的实现不合适。谁能建议我如何实现我的宁静客户端,以便在访问此 https url 时获得正常响应?

4

0 回答 0