赞
踩
当前主流的代理IP授权方式有两种,即绑定IP白名单和帐密验证。
简单说一下Android VpnService连接账密验证
//拼接
private String makeAuthorization() {
return Base64.encodeToString((m_Config.UserName + ":" + m_Config.Password).getBytes(), Base64.DEFAULT).trim();
}
//添加请求头
"Proxy-Authorization:Basic +makeAuthorization()
Tunnel连接中部分示例:
@Override protected void onConnected(ByteBuffer buffer) throws Exception { String request; if (TextUtils.isEmpty(m_Config.UserName) || TextUtils.isEmpty(m_Config.Password)) { request = String.format(Locale.ENGLISH, "CONNECT %s:%d HTTP/1.0\r\n" + "Proxy-Connection: keep-alive\r\n" + "User-Agent: %s\r\n" + "X-App-Install-ID: %s" + "\r\n\r\n", m_DestAddress.getHostName(), m_DestAddress.getPort(), ProxyConfig.Instance.getUserAgent(), ProxyConfig.AppInstallID); } else { request = String.format(Locale.ENGLISH, "CONNECT %s:%d HTTP/1.0\r\n" + "Proxy-Authorization: Basic %s\r\n" + "Proxy-Connection: keep-alive\r\n" + "User-Agent: %s\r\n" + "X-App-Install-ID: %s" + "\r\n\r\n", m_DestAddress.getHostName(), m_DestAddress.getPort(), makeAuthorization(), ProxyConfig.Instance.getUserAgent(), ProxyConfig.AppInstallID); } buffer.clear(); buffer.put(request.getBytes()); buffer.flip(); if (this.write(buffer, true)) { this.beginReceive(); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。