使用移動網絡異地請求數據

國慶回家,發現自己使用數據網絡,應用死活上不去了!但是對應的連接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.

但是,事實上調用是有效果的

     


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章