Cannot retry request with a non-repeatable request entity

前端 未结 2 1370
误落风尘
误落风尘 2020-12-16 17:32

I\'m using java-http-client library and Apache Transport with it on client side and Rails on server side. From time to time a get error like this:

11-24 17:3         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 18:15

    I have an similar error because I used CountingInputStreamEntity that is a non-repeteable http client. The solution was to use BufferedHttpEntity which converts the non-repeteable to repeteable httpclient.

    ParcelFileDescriptor fileDescriptor = this.getContentResolver().openFileDescriptor(uri, "r");
                InputStream in = this.getContentResolver().openInputStream(uri);
    
                CountingInputStreamEntity entity = new CountingInputStreamEntity(in, fileDescriptor.getStatSize());
                entity.setUploadListener(this);
                entity.setContentType("binary/octet-stream");
                entity.setChunked(true); 
            
                BufferedHttpEntity myEntity = null;
                try {
                    myEntity = new BufferedHttpEntity(entity);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                
                put.setEntity(myEntity);
    

提交回复
热议问题