gpt4 book ai didi

java - Android NTLM 获取 HTTP/1.1 401 未经授权

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:57:58 26 4
gpt4 key购买 nike

我正在尝试从共享点服务器获取数据。以下是我的代码。

    DefaultHttpClient httpclient = new DefaultHttpClient();

httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
httpclient.getCredentialsProvider().setCredentials(new AuthScope("masconsult.eu", -1),
new NTCredentials(username, password, "", ""));
HttpGet httpGet = new HttpGet(webserviceUrl);
httpGet.addHeader("Content-type", "application/json");
httpGet.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
// HttpResponse response="";
String responseXML = "";
HttpResponse response = httpclient.execute(httpGet);
response.getStatusLine().getReasonPhrase();
responseXML = EntityUtils.toString(response.getEntity());
Toast.makeText(this, responseXML, Toast.LENGTH_LONG).show();

我收到响应 HTTP/1.1 401 未经授权。即使我已经添加了所有正确的凭证。在 Chrome 浏览器中,它使用相同的凭据工作正常。请建议我对代码进行任何更改。

最佳答案

现在可以正常工作了。我用标题修改了我的代码。

 DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new NTCredentials(username, password, "", ""));
HttpGet httpGet = new HttpGet(webserviceUrl);
httpGet.addHeader("accept", "application/json;odata=verbose");
httpGet.addHeader("content-Type", "application/json;odata=verbose");
httpGet.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
HttpResponse response = httpclient.execute(httpGet);
System.out.println("Responseeee" + response.getStatusLine());
responseXML = EntityUtils.toString(response.getEntity());
new JSONObject(responseXML).toString();

关于java - Android NTLM 获取 HTTP/1.1 401 未经授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40760285/

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