0

请阅读我的帖子:

我需要使用以下参数将图像发布到 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 的请求。我环顾四周,但没有找到研究这个问题的好资源。

4

1 回答 1

1

以下可能会给你基本的想法

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);
于 2013-06-21T11:53:43.587 回答