HttpGet Digest授权认证
来源:互联网 发布:淘宝仓管工作职责 编辑:程序博客网 时间:2024/05/29 18:27
工具类: compile ‘com.burgstaller:okhttp-digest:1.13’
import android.content.Context;import com.burgstaller.okhttp.AuthenticationCacheInterceptor;import com.burgstaller.okhttp.CachingAuthenticatorDecorator;import com.burgstaller.okhttp.DispatchingAuthenticator;import com.burgstaller.okhttp.digest.CachingAuthenticator;import com.burgstaller.okhttp.digest.Credentials;import com.burgstaller.okhttp.digest.DigestAuthenticator;import java.io.IOException;import java.util.Map;import java.util.concurrent.ConcurrentHashMap;import okhttp3.Call;import okhttp3.Callback;import okhttp3.OkHttpClient;public class HttpUtils { private Context context; private CallBackResponse callback; static String resposes; public HttpUtils(Context context) { this.context = context; } public void setOnCallback(CallBackResponse callback) { this.callback = callback; } public interface CallBackResponse { void onSuccess(String response); } public void pullNews(String url) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>(); Credentials credentials = new Credentials("Hsp-2E9D30C1C1914BC7A14E17E257648563", "5894D3C2D891473E804A3814E5D61D4B");//授权用户名和密码 final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(credentials); DispatchingAuthenticator authenticator = new DispatchingAuthenticator.Builder().with("digest", digestAuthenticator).build(); okhttp3.Request request = new okhttp3.Request.Builder().url(url).get() .header("X-User-Id", "Hsp-2E9D30C1C1914BC7A14E17E257648563") .header("X-Google-Ad-Id", "5894D3C2D891473E804A3814E5D61D4B").build();//header OkHttpClient client = builder.authenticator(new CachingAuthenticatorDecorator(authenticator, authCache)) .addInterceptor(new AuthenticationCacheInterceptor(authCache)).build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, okhttp3.Response response) throws IOException { resposes = response.body().string(); if (callback != null) { callback.onSuccess(resposes); } } }); }}
阅读全文
0 0
- HttpGet Digest授权认证
- digest认证
- HTTP digest认证
- Http Digest认证协议
- Http Digest认证协议
- Http Digest认证协议
- Http Basic Digest 认证
- HTTP digest 认证
- Http Digest认证协议
- Http Digest认证协议
- Http Digest 认证
- http-digest的认证
- 签名认证算法Digest
- digest ~ 摘要认证
- Http认证之Digest认证
- basic认证,digest认证,NTLM认证
- SIP中的Digest认证过程
- 如何实现HTTP DIGEST认证
- 点滴学习Linux---- mail命令发送邮件
- 51nod 1444 破坏道路
- 什么是8K视频技术!8K视频测试解决方案
- java错误mark_1
- Vivado HLS 学习笔记(一)
- HttpGet Digest授权认证
- 逆天了我,abs在openjudge不能用(修改版)
- NDK开发 从入门到放弃(七:Android Studio 2.2 CMAKE 高效NDK开发)
- URL中“#” “?” &“”号的作用
- 本地 eclipse 远程调试服务器上的 tomcat
- 语义分割(semantic segmentation) 常用神经网络介绍对比-FCN SegNet U-net DeconvNet
- Maven库
- 微信浏览器横屏显示问题
- 监听EditText的内容长度