2012-06-08 48 views
3

有沒有辦法在android應用程序中添加代理IP和端口,以便通過代理路由互聯網訪問?在android代碼中設置代理IP和端口?

從一個鏈接我得到的信息

嘗試{ Settings.System.putString(getContentResolver(),
Settings.System.HTTP_PROXY,「127.0.0.1:100");//enable代理 } catch(Exception ex){ }

但是通過嘗試這個系統變量無法解析?

請幫忙!!

在此先感謝

+1

你能澄清你的問題嗎?你想添加一個通過瀏覽器進行網頁訪問的代理嗎?爲什麼你的應用程序想要更改瀏覽器代理? – Christine

+0

嗨,我的應用程序也應該與代理server.Android設備2.3.4直接沒有選項設置代理服務器。 – info

回答

1
HttpURLConnection con =null; 

URL url = new URL("xxxxx"); 

Proxy proxy=new Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(android.net.Proxy.getDefaultHost(),android.net.Proxy.getDefaultPort())); 

con = (HttpURLConnection) url.openConnection(proxy); 

這樣行嗎?