Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.6k stars 592 forks source link

No response when sending large file #353

Closed 799452017 closed 4 years ago

799452017 commented 4 years ago

Describe the bug Sending files larger than 100m stuck.

To Reproduce Steps to reproduce the behavior:

Unirest.post("xxx").field("file",new file("XXX")).asJson(); Expected behavior A clear and concise description of what you expected to happen.

Screenshots Is a zip file larger than 100m.

Environmental Data:

Additional context Add any other context about the problem here.

ryber commented 4 years ago

I think your problem may be on the receiving side, I can successfully upload files larger than 100m. You might add a progress monitor so see where it stops.

 HttpResponse<JsonNode> node = Unirest.post(xxx)
                .field("other", new File("/file.txt"))
                .uploadMonitor(new ProgressMonitor() {
                    @Override
                    public void accept(String field, String fileName, Long bytesWritten, Long totalBytes) {
                        System.out.println("bytesWritten = " + (totalBytes - bytesWritten));
                    }
                })
                .asJson();
799452017 commented 4 years ago

我认为您的问题可能在接收方,我可以成功上传大于100m的文件。您可能会添加一个进度监视器,以便查看它的停止位置。

 HttpResponse < JsonNode > node =  Unirest 。后(XXX)
                点域(“其他”,新的 文件(“ /file.txt ”))
                .uploadMonitor(新 ProgressMonitor(){
                     @覆盖
                    公共 无效 接受(字符串 场,字符串 文件名,龙 bytesWritten,龙 totalBytes){
                         系统。出来。println(“ bytesWritten = ”  +(totalBytes - bytesWritten)); 
                    } 
                ). 
                asJson();

Thank you for your reply,After observing the progress, I found that the log output of org.apache.http.wire debug caused the file to be sent very slowly, just like it was stuck. When I closed the log, the file sending was very smooth. Thank you.