2011-11-15 18 views
1

(特に私が接続不良の場合)NonRepeatableRequestExceptionを取得し、 をサーバーに送信しています。ここに私のコードは次のとおりです。NonRepeatableRequestExceptionサーバーに画像を送信中に

HttpParams params = new BasicHttpParams(); 

SchemeRegistry registry = new SchemeRegistry(); 
     registry.register(new Scheme("http", 
PlainSocketFactory.getSocketFactory(), 80)); 

DefaultHttpClient httpclient = new DefaultHttpClient(new 
ThreadSafeClientConnManager(params, registry), params); 

HttpPost httpPost = new HttpPost(uri); 
SimpleMultipartEntity multipartContent = new SimpleMultipartEntity(); 
multipartContent.addPart(propName, filename, inputStream, 
contentType); 
httpPost.setEntity(multipartContent); 
httpclient.getParams().setParameter("http.protocol.expect-continue", 
false); 

java.util.logging.Logger.getLogger("httpclient.wire.header").setLevel(java.util.logging.Level.FINEST); 
java.util.logging.Logger.getLogger("httpclient.wire.content").setLevel(java.util.logging.Level.FINEST); 
HttpResponse response = httpclient.execute(httpPost); 

私は、入力ストリームが非反復型であることを実現しますが、リクエストを適切に作成し、この例外を回避する方法は考えています。 何か助けていただければ幸いです。

答えて

0

は、私は私のHTTPClientのための私自身のDefaultHttpRequestRetryHandlerを追加できることがわかった。

httpclient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, false) { 

    public boolean retryRequest(IOException exception, int executionCount, 
      HttpContext context) { 
      if (executionCount > this.getRetryCount()) { 
       return false; 
      } 
      if (exception != null) { 
       return true; 
      } else { 
       return super.retryRequest(exception, executionCount, context); 
      } 

    } 
}); 
0

私はこの例外の理由の一つが提起されることが判明しました。

this groupによると、サーバーがHTTP 401(Unauthorized)を返すため、この例外が発生する可能性があります。

関連する問題