JAVA HttpPost enctype=";“多种形式/数据”;
我正在尝试使用JAVA HttpPost enctype=";“多种形式/数据”;,java,http,http-headers,httpclient,Java,Http,Http Headers,Httpclient,我正在尝试使用HttpClient 4.2.3 形式类似于 <form action="localhost/xyz.aspx" method = "post" enctype="multipart/form-data"> <input type="text" name="name"> <input type="text" name="age"> <input type="text" name="submit"> <
HttpClient 4.2.3
形式类似于
<form action="localhost/xyz.aspx" method = "post" enctype="multipart/form-data">
<input type="text" name="name">
<input type="text" name="age">
<input type="text" name="submit">
</form>
我仍然会遇到一个错误,比如HTTP 415 HTTP 400
有人能帮我模拟一下这样的要求吗
TIA您正在发送的多部分实体需要设置两个对象
FileBody
和StringBody
。您正在设置的只是StringBody
简言之,多部分请求通常由文件组成。服务器需要文件名(使用StringBody
设置)和文件内容(使用FileBody
设置)
比如说
FileBody name = new FileBody(new File(fileName));
StringBody content = new StringBody("Filename: " + fileName);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("name", bin);
reqEntity.addPart("content", content);
httppost.setEntity(reqEntity);
在您的情况下,您似乎没有发送任何mutlipart内容。我不确定您是否使用了该编码类型 这个问题可能会对你有所帮助:@Andremoniy我也尝试过同样的方法,结果没有发现任何内容配置,如果可能的话,你甚至可以在这方面提供帮助。TIAi不必发送任何文件内容。我只是逆向工程jBPM控制台。所以我必须模拟相同的请求。如果我错了,请详细说明。只需从代码中删除与多部分相关的内容,并检查其是否有效。@Santhosh我实际上正在尝试同样的事情。
MultipartEntity entity = new MultipartEntity();
entity.addPart("name",new StringBody("john",Charset.forName("UTF-8")));
entity.addPart("age", new StringBody("10",Charset.forName("UTF-8")));
FileBody name = new FileBody(new File(fileName));
StringBody content = new StringBody("Filename: " + fileName);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("name", bin);
reqEntity.addPart("content", content);
httppost.setEntity(reqEntity);