真郁闷,前段时间一直纠结的事情,就这么容易解决了
1. private HttpURLConnection getURLConnection(String url) throws Exception {
2. String proxyHost = android.net.Proxy.getDefaultHost();
3. if (proxyHost != null) {
4. java.net.Proxy p = new java.net.Proxy(java.net.Proxy.Type.HTTP,
5. new InetSocketAddress(android.net.Proxy.getDefaultHost(),
6. android.net.Proxy.getDefaultPort()));
7.
8. return (HttpURLConnection) new URL(url).openConnection(p);
9.
10. } else {
11. return (HttpURLConnection) new URL(url).openConnection();
12. }
13. }