gpt4 book ai didi

不支持 Android 身份验证方案 ntlm

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:49:51 26 4
gpt4 key购买 nike

我正在使用 asynhttpClient 进行基本身份验证

http://loopj.com/android-async-http/

那是 looj 库..

下面是我的代码:

用户名随 secret 码=用户名+“:”+密码;

            Log.d("username=",usernameRandomPassword);
Log.d("url=",url);
String authorization = "Basic " + Base64.encodeToString(usernameRandomPassword.getBytes("UTF-8"), Base64.NO_WRAP);
httpClient.addHeader("Authorization",authorization);
httpClient.addHeader("Content-type", "application/json");
httpClient.setTimeout(20000);

httpClient.get( url, new AsyncHttpResponseHandler() {

@Override
public void onStart() {
System.out.println("on satrt");
super.onStart();
}

@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {

System.out.println("on onSuccess statusCode="+statusCode);
toastmessgae("onSuccess status code="+statusCode);
super.onSuccess(statusCode, headers, responseBody);
}

@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

System.out.println("on onFailure="+statusCode);
toastmessgae("onFailure status code="+statusCode);
super.onFailure(statusCode, headers, responseBody, error);

}

@Override
public void onFinish() {
System.out.println("on onFinish");
super.onFinish();
}
});



} catch (UnsupportedEncodingException e) {

}

但我总是在控制台收到 401,下面是日志

不支持身份验证方案 ntlm。
无法响应以下任何挑战:{ntlm=WWW-Authenticate: NTLM, negotiate=WWW-Authenticate: Negotiate}

我在直接链接上检查的凭据是正确的。

我已经在这上面花了整整一天了,有人可以帮我吗?如果您分享一些示例,那将非常有帮助。

提前致谢..

最佳答案

这里是通过代码给出的答案:

将下面的代码添加到你的android文件中

            DefaultHttpClient httpclient = new DefaultHttpClient();
// register ntlm auth scheme
httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
httpclient.getCredentialsProvider().setCredentials(
// Limit the credentials only to the specified domain and port
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
// Specify credentials, most of the time only user/pass is needed
new NTCredentials(username, password, "", "")
);

HttpUriRequest httpget = new HttpGet(your_URL);
HttpResponse response = httpclient.execute(httpget);
String responseBody = EntityUtils.toString(response.getEntity());
Log.i(tag,"responseBody =>>>>>>>>>>"+responseBody);

现在从

下载lib和java文件

https://github.com/masconsult/android-ntlm

并将 jcifs-1.3.17.jar 复制到您的 lib 文件夹中JCIFSEngine 和 NTLMSchemeFactory 到你的包。 (如果你愿意,你可以改变包装..)

至此,您的应用已准备好运行。

更有用的链接:

http://www.developergarden.com/en/marketplace/components/details/cmp/android-ntlm-authentication/

关于不支持 Android 身份验证方案 ntlm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20505207/

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