使用移动网络异地请求数据
国庆回家,发现自己应用死活上不去了!但是对应的连接UC访问无压力,因为负责网络请求部分,把我吓个半死
回来查了好多资料,才发现是因为代理发生了变化,但是对应请求没有设置,导致无法访问
解决方案:
1、HttpClient
if(!NetUtil.isWiFiActive(context)){ String host=Proxy.getDefaultHost(); int port = Proxy.getPort(context); if(!TextUtils.isEmpty(host)){ HttpHost httpHost = new HttpHost(host, port); httpClient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY,httpHost); } }只需要在load前,调用方法 WebView.enablePlatformNotifications(); 就ok了
虽然这个文档中说
This method is now obsolete
Enables platform notifications of data state and proxy changes. Notifications are enabled by default.
但是,事实上调用是有效果的