[英]Sending a key and file using MultipartEntityBuilder
我在网络方面没有太多经验,而且我的Google搜寻技巧似乎并没有比这更进一步。
我需要将文件“ file”作为HTTP POST密钥发送到服务器。 这是我所拥有的:
MultipartEntityBuilder mpEntity = MultipartEntityBuilder.create();
mpEntity.addBinaryBody("file", image);//set up the object to send
HttpPut put = new HttpPut("http://address:port");
put.setEntity(mpEntity.build());//put the object to be sent
//try sending
try {
HttpResponse response = client.execute(put);
...
使用InputStream
处理响应时出现404错误。 服务器已启动并正在运行,并且可以在终端上对其进行测试。
将内容类型和文件名添加到二进制主体中,如下所示:
mpEntity.addBinaryBody("file", image, ContentType.create("image/jpeg"), "image_name.jpg");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.