0

我正在编写一个 Android 应用程序。当我使用时,它会向服务器发送 HTTPPost 并接收答案:

public final HttpResponse execute (HttpUriRequest request)

没关系,

但是当我尝试使用时:

public T execute (HttpUriRequest request, ResponseHandler<? extends T> responseHandler)

它抛出ClientProtocolException

由于某些原因我想使用第二个功能,我该怎么办?有什么例外?

这是使用第一个函数的代码:

  HttpPost httppost = new HttpPost("http://foo.Com/GeneralControls/Service.asmx/Login");
  DefaultHttpClient httpclient = new DefaultHttpClient(); 
  HttpResponse response =  httpclient.execute(httppost) ;

这是使用第二个函数的代码:

   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) ;

抛出 ClientProtocolException。

4

2 回答 2

0

请参阅下面的代码对我来说工作正常

        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

于 2013-07-05T11:27:07.227 回答
0

问题是协议问题,网络服务正在更改目标 URL 并产生异常

于 2013-08-10T08:49:16.487 回答