gpt4 book ai didi

android - Android 上的基本身份验证

转载 作者:太空宇宙 更新时间:2023-11-03 11:18:33 25 4
gpt4 key购买 nike

我找到了一个例子

try {
String data = "YOUR REQUEST BODY HERE";
//
CredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials("YOUR USER NAME HERE", "YOUR PASSWORD HERE"));
//
DefaultHttpClient http = new DefaultHttpClient();
http.setCredentialsProvider(credProvider);
//
HttpPut put = new HttpPut("YOUR HTTPS URL HERE");
try {
put.setEntity(new StringEntity(data, "UTF8"));
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "UnsupportedEncoding: ", e);
}
put.addHeader("Content-type","SET CONTENT TYPE HERE IF YOU NEED TO");
HttpResponse response = http.execute(put);
Log.d(TAG, "This is what we get back:"+response.getStatusLine().toString()+", "+response.getEntity().toString());
} catch (ClientProtocolException e) {
//
Log.d(TAG, "Client protocol exception", e);
} catch (IOException e) {
//
Log.d(TAG, "IOException", e);
}

但我必须以授权格式发送一个字符串:<Login>@<ID>:<Passsword>

如何做到这一点?

最佳答案

您确定您的服务器确实在使用基本身份验证吗?如果是,您应该像这样设置凭据:

new UsernamePasswordCredentials("Login@ID", "Passsword");

否则检查实际的身份验证协议(protocol)是什么并实现它(在 header 中发送身份验证信息,或作为 URL 的一部分或作为 POST 参数等)

关于android - Android 上的基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12806023/

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