Cannot retry request with a non-repeatable request entity

前端 未结 2 1358
误落风尘
误落风尘 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);
    
    0 讨论(0)
  • I solved it as folllows:

    MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
    entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    ContentType contentType = ContentType.create("image/jpeg", Consts.ISO_8859_1);
    entityBuilder.addBinaryBody(PARAM_ATTACHMENT, new File(filepath), contentType, StringUtils.getFileName(filepath));
    
    0 讨论(0)
提交回复
热议问题