共享点的Java RESTful客户端连接抛出403禁止错误

时间:2019-02-10 17:58:10

标签: java authentication sharepoint

我可以访问由公司SAML进行身份验证的共享点。我必须连接到URL https://xyz.sharepoint.com/teams/x/y/z/teams.aspx,并且必须从此页面下载文件。我已经使用下面的代码进行连接,并且正在获取HTTP / 1.1 403 Forbidden

公共类SharePointAuthenticator {

private static final String ASIAPACIFIC_HPQCORP_NET = "asiapacific.hpqcorp.net";

public static void main(String[] args) throws Exception {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(
            new AuthScope(AuthScope.ANY),
            new NTCredentials("ntusername", "password", "http://localhost", "domain"));
    CloseableHttpClient httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
            .build();
    try {
        System.out.println("Inside try");
        HttpGet httpget = new HttpGet("https://xyz.sharepoint.com/teams/myapps/_api/web");

        System.out.println("Executing request " + httpget.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httpget);
        try {
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            EntityUtils.consume(response.getEntity());
        } finally {
            response.close();
        }
    } finally {
        httpclient.close();
    }
}

}

执行请求GET https://xyz.sharepoint.com/teams/myapps/_api/web HTTP / 1.1

禁止使用HTTP / 1.1 403

请问这里有什么问题吗?

0 个答案:

没有答案