Java 多部分JSON POST请求

Java 多部分JSON POST请求,java,json,web-services,rest,Java,Json,Web Services,Rest,请阅读我的帖子: 我需要使用以下参数将图像发布到JSON WS: Content-Type: multipart/related; boundary="foo_bar_baz" Content-Length: {number_of_bytes_in_entire_request_body} -- Check your rest client API's. Some would automatically determine content-length at

请阅读我的帖子:

我需要使用以下参数将图像发布到JSON WS:

Content-Type: multipart/related; boundary="foo_bar_baz"
Content-Length: {number_of_bytes_in_entire_request_body} -- Check your rest client                   API's. Some would automatically determine content-length at runtime. Eg. jersey client api.
 --foo_bar_baz
Content-Type: application/json;
{
"filename": "cloudx.jpg"
}
--foo_bar_baz
Content-Type: image/jpeg
{JPEG data}
--foo_bar_baz--

我正在构建Android应用程序,我需要编写将图像发送到上述WS的请求。我四处寻找了一段时间,没有找到好的资源来研究这个问题

下面可能会给你一些基本的想法

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(<URI>);
HttpEntity entity = new FileEntity(file,ContentType.MULTIPART_FORM_DATA);
//there are other types of entities and content types too check documentation
req.setEntity(entity);
HttpResponse response = httpClient.execute(req);
HttpClient=newdefaulthttpclient();
HttpPost=新的HttpPost();
HttpEntity=新文件实体(文件,ContentType.MULTIPART\u表单\u数据);
//还有其他类型的实体和内容类型也可以查看文档
请求设置实体(实体);
HttpResponse response=httpClient.execute(req);

Apache http客户端应该具有多部分支持。我同意,但我仍然不知道如何使用这3个头创建请求。。我想我真的需要一个关于这个的代码。。谷歌是你的朋友<代码>java多部分请求