最近项目网络请求需要设置代理,记录一下。
http和https都可以。
OkHttpClient.Builder builder = new OkHttpClient.Builder();
//代理服务器的IP和端口号
builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)));
//代理的鉴权账号密码
final String userName = "";
final String password = "";
builder.proxyAuthenticator(new Authenticator() {
ijkplayer设置代理和账号密码
mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,"http_proxy", "http://"+host + ":" + port);
mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,"headers", "Proxy-Authorization:"+credential);