gpt4 book ai didi

java - HttpClient 4.3.6 返回 "WARNING: NEGOTIATE authentication error"

转载 作者:搜寻专家 更新时间:2023-11-01 01:33:53 24 4
gpt4 key购买 nike

我在 Java 6 中运行 HttpClient 4.3.6。当我运行以下代码时,身份验证似乎成功了。返回的状态代码为 200。但是,我在控制台中收到以下错误消息:

警告:NEGOTIATE 身份验证错误:提供的名称无效(机制级别:无法加载配置文件 C:\Windows\krb5.ini(系统找不到指定的文件))

如何消除此警告?

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpContext localContext = new BasicHttpContext();
HttpGet method = new HttpGet(url);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(host, 80),
new NTCredentials(userid, password, host, login_domain));

localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, credsProvider);

String filePath = null;

// Execute the method.
CloseableHttpResponse clientResponse = httpclient.execute(method, localContext);

HttpEntity entity = clientResponse.getEntity();

int statusCode = clientResponse.getStatusLine().getStatusCode();

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getRequestLine());
}

最佳答案

您需要传入一组目标首选身份验证方案:

像这样创建你的 httpClient:

PoolingHttpClientConnectionManager connPool = new PoolingHttpClientConnectionManager();

connPool.setMaxTotal(200);
connPool.setDefaultMaxPerRoute(200);

// Authentication
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new NTCredentials(username, password, workstation, domain));


RequestConfig config = RequestConfig.custom().setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM)).build();

CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connPool).setDefaultRequestConfig(config).build();

HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);

关于java - HttpClient 4.3.6 返回 "WARNING: NEGOTIATE authentication error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27277297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com