Java httpclient.execute起作用,但重载函数引发异常
我正在写一个Android应用程序。当我使用以下命令时,它会向服务器发送HTTPPost并接收响应:Java httpclient.execute起作用,但重载函数引发异常,java,android,httpresponse,Java,Android,Httpresponse,我正在写一个Android应用程序。当我使用以下命令时,它会向服务器发送HTTPPost并接收响应: 公共最终HttpResponse执行(HttpUriRequest请求) 没关系 但当我尝试使用: public T execute(HttpUriRequest请求,ResponseHandler请看下面的代码对我来说运行良好 HttpContext localContext = new BasicHttpContext(); localContext.setA
公共最终HttpResponse执行(HttpUriRequest请求)
没关系
但当我尝试使用:
public T execute(HttpUriRequest请求,ResponseHandler请看下面的代码对我来说运行良好
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE,
Util.cookieStore);
try {
HttpResponse response = httpclient.execute(httppost,
localContext);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
但是您正在尝试传递ResponseHandler,它接受httpContext。问题是协议问题,Web服务正在更改目标URL,并产生异常
HttpPost httppost = new HttpPost("http://foo.Com/GeneralControls/Service.asmx/Login");
DefaultHttpClient httpclient = new DefaultHttpClient();
ResponseHandler<String> responseHandler=new BasicResponseHandler();
String response = httpclient.execute(httppost , responseHandler) ;
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE,
Util.cookieStore);
try {
HttpResponse response = httpclient.execute(httppost,
localContext);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}