-1

I constructed an HttpClient, and set timeout parameters.

the code is like this:

while(bufferedinputstream.read()!=-1){

    post.setEntity(multipartEntity);
    HttpResponse response = httpClient.excute(post);
}

it worked fine for the first several request, and then somehow the response is not returned, and no exception or timeout exception was thrown. Anyone has any idea what's happening?

4

1 回答 1

-1

由于您没有收到任何错误或异常(您是否将它们打印出来?),您可以检查您的回复的 satusCode。也许它有帮助。

(我的 AsyncTask 中的重写方法)

protected String doInBackground(String... arg) {
    String url = arg[0]; // Added this line
    //...

    Log.i(DEBUG_TAG, "URL CALL -> " + url);

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);

    String mResponse = "";
    try {

         List<NameValuePair> params = new LinkedList<NameValuePair>();
         //...

         post.setEntity(new UrlEncodedFormEntity(params));

        HttpResponse mHTTPResponse = client.execute(post);

        StatusLine statusLine = mHTTPResponse.getStatusLine();
        int statusCode = statusLine.getStatusCode();

        if (statusCode == 200) { // 

            //get response
            BufferedReader rd = new BufferedReader(new InputStreamReader(
                    mHTTPResponse.getEntity().getContent()));

            StringBuilder builder = new StringBuilder();
            String aux = "";

            while ((aux = rd.readLine()) != null) {
                builder.append(aux);
            }

            mResponse = builder.toString();

        } else {
            //cancel task and show error
            Log.e(DEBUG_TAG, "ERROR in Request:" + statusCode);
            this.cancel(true);
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return mResponse;
}
于 2013-05-22T16:43:01.797 回答