日期:2014-05-20  浏览次数:20826 次

HttpClient client = new HttpClient();??
HttpClient client = new HttpClient();
小弟刚学HttpClient ,最近网上查看的教程,为什么看到大家都是按上面的来创建一个对象啊。我去下的httpclient,也按这样创建了,但不管怎么弄都报错,而只能HttpClient client = new Default HttpClient();这样才没有报错!!!WHY??
------解决方案--------------------
HttpClient client = new HttpClient() {

@Override
public HttpParams getParams() {
// TODO Auto-generated method stub
return null;
}

@Override
public ClientConnectionManager getConnectionManager() {
// TODO Auto-generated method stub
return null;
}

@Override
public <T> T execute(HttpHost arg0, HttpRequest arg1,
ResponseHandler<? extends T> arg2, HttpContext arg3)
throws IOException, ClientProtocolException {
// TODO Auto-generated method stub
return null;
}

@Override
public <T> T execute(HttpHost arg0, HttpRequest arg1,
ResponseHandler<? extends T> arg2) throws IOException,
ClientProtocolException {
// TODO Auto-generated method stub
return null;
}

@Override
public <T> T execute(HttpUriRequest arg0,
ResponseHandler<? extends T> arg1, HttpContext arg2)
throws IOException, ClientProtocolException {
// TODO Auto-generated method stub
return null;
}

@Override
public HttpResponse execute(HttpHost arg0, HttpRequest arg1,
HttpContext arg2) throws IOException,
ClientProtocolException {
// TODO Auto-generated method stub
return null;
}

@Override
public <T> T execute(HttpUriRequest arg0,
ResponseHandler<? extends T> arg1) throws IOException,
ClientProtocolException {
// TODO Auto-generated method stub
return null;
}

@Override
public HttpResponse execute(HttpHost arg0, HttpRequest arg1)
throws IOException, ClientProtocolException {
// TODO Auto-generated method stub
return null;
}

@Override
public HttpResponse execute(HttpUriRequest arg0, HttpContext arg1)
throws IOException, ClientProtocolException {
// TODO Auto-generated method stub
return null;
}

@Override
public HttpResponse execute(HttpUriRequest arg0)
throws IOException, ClientProtocolException {
// TODO Auto-generated method stub
return null;
}
};



public class DefaultHttpClient extends AbstractHttpClient 

public abstract class AbstractHttpClient implements HttpClient

从以上关系可以看出,要用HttpClient就要实现它的接口,一般用他实现类的父类就行了,也就是DefaultHttpClient。