國慶回家,發現自己使用數據網絡,應用死活上不去了!但是對應的連接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);
}
}
2、WebView
只需要在load前,調用方法 WebView.enablePlatformNotifications(); 就ok了
雖然這個文檔中說
This method is now obsolete
Enables platform notifications of data state and proxy changes. Notifications are enabled by default.
但是,事實上調用是有效果的