【问题标题】:MultipartEntity post arrayMultipartEntity 后数组
【发布时间】: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


    【解决方案1】:

    ..好吧,我想我找到了办法。

    ....
    entity.addPart("newfile[caption]", new StringBody("myCaption"));
    entity.addPart("newfile[file]", new FileBody(file));
    entity.addPart("uploadername", new StringBody("myName"));
    ...
    

    【讨论】:

      猜你喜欢
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 2013-10-12
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 2013-06-22
      相关资源
      最近更新 更多