【发布时间】:2014-11-27 05:59:49
【问题描述】:
我正在尝试使用 http 发布请求上传文件。我认为使用 MultipartEntity 是可行的,例如:
MultipartEntity entity = new MultipartEntity();
...
entity.addPart("caption", new StringBody("myCaption"));
entity.addPart("file", new FileBody(file));
entity.addPart("uploadername", new StringBody("myName"));
...
我现在的问题是发布请求的结构。 而不是相当简单的......
{
"caption":[caption],
"file":[file to upload],
"uploadername":[name]
}
..它是..
{
"newfile":
{
"caption":[caption],
"file":[file to upload]
},
"uploadername":[name]
}
如果我不需要发布文件,我可以使用 JSONObject 并将一个 JSONObject 放入另一个 JSONObject 中,但我无法为 MultipartEntity 找到这样做的方法。 有什么线索吗?提前致谢。
【问题讨论】:
标签: android file http multipartentity