我从这里使用了相同的代码,只做了很少的改动:
Downloading File in Android
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
"Myproxy", 8080));
URL url = new URL(sUrl[0]);
HttpURLConnection uc = (HttpURLConnection) url
.openConnection(proxy);
uc.connect();
int fileLength = uc.getContentLength();
我收到以下异常:
04-12 09:31:42.401: WARN/System.err(5181): java.net.UnknownHostException: Host is unresolved: Myproxy:8080
04-12 09:31:42.405: WARN/ System.err(5181): at java.net.Socket.connect(Socket.java:1057)
04-12 09:31:42.405: WARN/System.err(5181): at org.apache.harmony.luni.internal .net.www.protocol.http.HttpConnection.(HttpConnection.java:62)
04-12 09:31:42.405: WARN/System.err(5181): at org.apache.harmony.luni.internal.net.www .protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
04-12 09:31:42.405: WARN/System.err(5181): at org.apache.harmony.luni.internal.net.www.protocol。 http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
04-12 09:31:42.409: WARN/System.err(5181): 在 org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:884)
04-12 09:31:42.409: WARN/System.err(5181): 在 com.test.filedownload.FileDownloadActivity$DownloadFile.doInBackground(FileDownloadActivity.java:99)
04-12 09:31:42.413: WARN/System.err(5181 ): 在 com.test.filedownload.FileDownloadActivity$DownloadFile.doInBackground(FileDownloadActivity.java:1)
04-12 09:31:42.416: WARN/System.err(5181): 在 android.os.AsyncTask$2.call(AsyncTask .java:185)
04-12 09:31:42.420: WARN/System.err(5181): 在 java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-12 09:31:42.420: WARN/System.err(5181): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-12 09:31:42.420: WARN/System.err( 5181): 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-12 09:31:42.424: WARN/System.err(5181): 在 java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:561)
04-12 09:31:42.424: WARN/System.err(5181): at java.lang.Thread.run(Thread.java:1096)
请帮助解决同样的问题。
谢谢,
斯内哈