某些手机管家软件在手机连接上CMCC等wifi时,会弹出通知栏提示跳转到webview去进行portal验证。
他们是怎么检测的呢?有知道的麻烦通知下。万谢。
我在网上也搜了些资料,说对于这种wlan,android发起一个http请求,会返回一个302的重定向的报文,然后去获取“location”的重定向地址。但是不成功,下面是我的代码,请大牛帮忙看下到底是哪里出现的问题
他们是怎么检测的呢?有知道的麻烦通知下。万谢。
我在网上也搜了些资料,说对于这种wlan,android发起一个http请求,会返回一个302的重定向的报文,然后去获取“location”的重定向地址。但是不成功,下面是我的代码,请大牛帮忙看下到底是哪里出现的问题
//禁止android自动执行重定向
public class RedirectHandler extends DefaultRedirectHandler {
@Override
public boolean isRedirectRequested(HttpResponse response,
HttpContext context) {
return false;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HttpPost httppost = new HttpPost(PortalActivity.TEST_URL);
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
RedirectHandler redirectHandler=new RedirectHandler();
//禁止android自动执行重定向
httpClient.setRedirectHandler(redirectHandler);
HttpResponse response=httpClient.execute(httppost);
int state = response.getStatusLine().getStatusCode();
if(state == 302){
Header[] headers = response.getAllHeaders();
for(Header h : headers){
if("location".equalsIgnoreCase(h.getName())){
return h.getValue();
}
}
}
} catch (Exception e) {
return null
}