How can I get a custom Content-Disposition line using Apache httpclient?

后端 未结 2 2011
抹茶落季
抹茶落季 2021-01-12 13:09

I am using the answer here to try to make a POST request with a data upload, but I have unusual requirements from the server-side. The server is a PHP script wh

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-12 13:34

    Try this

    StringBody stuff = new StringBody("stuff");
    FormBodyPart customBodyPart = new FormBodyPart("file", stuff) {
    
        @Override
        protected void generateContentDisp(final ContentBody body) {
            StringBuilder buffer = new StringBuilder();
            buffer.append("form-data; name=\"");
            buffer.append(getName());
            buffer.append("\"");
            buffer.append("; filename=\"-\"");
            addField(MIME.CONTENT_DISPOSITION, buffer.toString());
        }
    
    };
    MultipartEntity entity = new MultipartEntity();
    entity.addPart(customBodyPart);
    

提交回复
热议问题