Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA HttpPost enctype=";“多种形式/数据”;_Java_Http_Http Headers_Httpclient - Fatal编程技术网

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);