下了一个httpclient-4.1.1.jar,写了最简单的例子,跑起来却报错,大家看看,这是为啥呢?
HttpResponse response = null;
DefaultHttpClient httpclient = new DefaultHttpClient();
//HttpPost httppost = new HttpPost("http://www.baidu.com");
HttpGet httpget = new HttpGet("http://www.baidu.com/");
try {
response = httpclient.execute(httpget);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
报如下错误
05-04 02:01:03.005: WARN/System.err(361): java.net.UnknownHostException: www.baidu.com
05-04 02:01:03.015: WARN/System.err(361): at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
05-04 02:01:03.015: WARN/System.err(361): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
05-04 02:01:03.025: WARN/System.err(361): at java.net.InetAddress.getAllByName(InetAddress.java:242)
05-04 02:01:03.034: WARN/System.err(361): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
05-04 02:01:03.034: WARN/System.err(361): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-04 02:01:03.034: WARN/System.err(361): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-04 02:01:03.054: WARN/System.err(361): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
05-04 02:01:03.054: WARN/System.err(361): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-04 02:01:03.065: WARN/System.err(361): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-04 02:01:03.065: WARN/System.err(361): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-04 02:01:03.074: WARN/System.err(361): at com.http.test.main.onCreate(main.java:26)
05-04 02:01:03.074: WARN/System.err(361): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-04 02:01:03.074: WARN/System.err(361): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-04 02:01:03.084: WARN/System.err(361): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-04 02:01:03.094: WARN/System.err(361): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-04 02:01:03.094: WARN/System.err(361): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-04 02:01:03.094: WARN/System.err(361): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 02:01:03.104: WARN/System.err(361): at android.os.Looper.loop(Looper.java:123)
05-04 02:01:03.104: WARN/System.err(361): at android.app.ActivityThread.main(ActivityThread.java:4627)