How to upload a file using Java HttpClient library working with PHP

前端 未结 10 2357
旧巷少年郎
旧巷少年郎 2020-11-22 08:48

I want to write Java application that will upload a file to the Apache server with PHP. The Java code uses Jakarta HttpClient library version 4.0 beta2:

impo         


        
10条回答
  •  鱼传尺愫
    2020-11-22 09:03

    I ran into the same problem and found out that the file name is required for httpclient 4.x to be working with PHP backend. It was not the case for httpclient 3.x.

    So my solution is to add a name parameter in the FileBody constructor. ContentBody cbFile = new FileBody(file, "image/jpeg", "FILE_NAME");

    Hope it helps.

提交回复
热议问题