0

私はAndroidアプリケーションを書いています。HTTPPost をサーバーに送信し、次を使用すると回答を受け取ります。

public final HttpResponse execute (HttpUriRequest request)

大丈夫です、

しかし、私が使用しようとすると:

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

それは投げますClientProtocolException

何らかの理由で 2 番目の関数を使用したいのですが、どうすればよいですか? の例外は何ですか?

最初の関数を使用するコードは次のとおりです。

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

2 番目の関数を使用するコードは次のとおりです。

   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

問題はプロトコルの問題でした。Web サービスが宛先 URL を変更していて、例外が発生しました。

于 2013-08-10T08:49:16.487 に答える
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 に答える