Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 协商身份验证错误:(机制级别:未提供有效凭据(未能找到任何Kerberos tgt))-Microsoft SharePoint API_Java_Sharepoint_Wget_Kerberos_Apache Httpclient 4.x - Fatal编程技术网

Java 协商身份验证错误:(机制级别:未提供有效凭据(未能找到任何Kerberos tgt))-Microsoft SharePoint API

Java 协商身份验证错误:(机制级别:未提供有效凭据(未能找到任何Kerberos tgt))-Microsoft SharePoint API,java,sharepoint,wget,kerberos,apache-httpclient-4.x,Java,Sharepoint,Wget,Kerberos,Apache Httpclient 4.x,我正试图从SharePointAPI下载一些Json格式的数据。我可以使用WGET来做这件事,我正试图用Java程序来做同样的事情。下面是我的代码: CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST,AuthScope.ANY_PORT),

我正试图从
SharePoint
API下载一些
Json
格式的数据。我可以使用
WGET
来做这件事,我正试图用Java程序来做同样的事情。下面是我的代码:

CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST,AuthScope.ANY_PORT),
                new NTCredentials("username","password",null,"sharepoint2.domain.com"));

HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();

try {
    HttpGet jsonGet = new HttpGet("URL");      
    jsonGet.setHeader("Accept","Application/json;odata=verbose");
        HttpResponse json = httpClient.execute(jsonGet);
        System.out.println(json.toString());
        System.out.println(json.getStatusLine());
        System.out.println(json.getEntity().toString());
} catch (Exception e){
    e.printStackTrace();
}
当我运行上述代码时,我得到以下错误:

WARNING: NEGOTIATE authentication error: No valid credentials provided (Mechanism level: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt))
HttpResponseProxy{HTTP/1.1 401 Unauthorized [Server: Microsoft-IIS/8.5, SPRequestGuid: 8dd6489e-f91e-1018-e731-4711c8a5147c, request-id: 8dd6489e-f91e-1018-e731-4711c8a5147c, SPRequestDuration: 23, SPIisLatency: 0, WWW-Authenticate: NTLM, WWW-Authenticate: Negotiate, X-Powered-By: ASP.NET, MicrosoftSharePointTeamServices: 15.0.0.4859, X-Content-Type-Options: nosniff, X-MS-InvokeApp: 1; RequireReadOnly, Date: Fri, 09 Feb 2018 15:43:03 GMT, Content-Length: 0]
我对kerberos的了解有限,不理解错误的含义。我正在使用与
WGET
相同的kerberos票证运行java程序。它适用于
WGET
,但不确定它为什么会在Java程序中抛出错误

下面是我的WGET命令的输出:

$wget --user username --password password --header='Accept: application/json;odata=verbose' "URL"
--2018-02-09 10:20:55--  'URL'
Resolving sharepoint2.domain.com... xxx.xxx.xxx.xxx
Connecting to sharepoint2.domain.com|xxx.xxx.xxx.xxx|:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Reusing existing connection to sharepoint2.domain.com:80.
HTTP request sent, awaiting response... 401 Unauthorized
Reusing existing connection to sharepoint2.domain.com:80.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/json]
Saving to: “items?$top=1000.7”
从输出中,我看到它尝试授权并失败两次,然后使用现有连接。我不知道为什么会这样

那么,我如何让我的java程序工作来做与wget相同的事情呢?任何帮助都将不胜感激,谢谢

更新:

我试着像这样设置
krb5.conf
jass.conf

System.setProperty("java.security.krb5.conf","path");
System.setProperty("java.security.auth.login.config","path");
但是,它仍然给我同样的错误