我正在尝试使用 发送GET
请求HttpClient
,但我不断收到IllegalStateException
. 知道是什么原因造成的吗?我一直在寻找解决方案,但我不明白"host=null"
日志中的含义。如何设置主机,它与路径有何不同?这是我的日志:
07-17 11:54:18.002: W/System.err(15422): java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=google.com
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:591)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.AbstractHttpClient$1.executeRequestSending(AbstractHttpClient.java:609)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.naf.redirect.NafRequestExecutorWrapperRedirectionHandler.executeRequestSendingUsual(NafRequestExecutorWrapperRedirectionHandler.java:96)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.naf.redirect.NafRequestExecutorWrapperRedirectionHandler.executeRequestSending(NafRequestExecutorWrapperRedirectionHandler.java:73)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.naf.auth.NafHttpAuthStrategyDefault.sendFirstRequest(NafHttpAuthStrategyDefault.java:487)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.naf.auth.NafHttpAuthStrategyDefault.performAuthExecutionUnsafe(NafHttpAuthStrategyDefault.java:388)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.naf.auth.NafHttpAuthStrategyDefault.performAuthExecution(NafHttpAuthStrategyDefault.java:200)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:558)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:508)
07-17 11:54:18.002: W/System.err(15422): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:486)
07-17 11:54:18.002: W/System.err(15422): at myapp.httprequest.free.GETActivity$1sendRequestTask.doInBackground(GETActivity.java:102)
07-17 11:54:18.002: W/System.err(15422): at myapp.httprequest.free.GETActivity$1sendRequestTask.doInBackground(GETActivity.java:1)
07-17 11:54:18.002: W/System.err(15422): at android.os.AsyncTask$2.call(AsyncTask.java:264)
07-17 11:54:18.002: W/System.err(15422): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-17 11:54:18.002: W/System.err(15422): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-17 11:54:18.002: W/System.err(15422): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-17 11:54:18.002: W/System.err(15422): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-17 11:54:18.002: W/System.err(15422): at java.lang.Thread.run(Thread.java:856)
和来源:
HttpClient getClient = new DefaultHttpClient();
HttpGet getData = new HttpGet(this.address);
try {
HttpResponse gameResponse = getClient.execute(getData);
return EntityUtils.toString(gameResponse.getEntity());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}