我有一个非常简单的请求,但HttpPoison似乎无法解决。
该请求包含附件,因此我使用的是multipart/form-data
内容类型。
当我只发送文件时,请求可以正常工作,但是我需要在请求中添加其他一些道具,这就是问题所在。
我的请求:
HTTPoison.post(
"path.com/api/anything",
{:multipart, [
{
:file,
"/path/file.xlsx",
{"form-data", [name: "file", filename: "file.xlsx"]}, []
},
{"taskName", "#{task.name}"},
{"taskLink", "#{task.link}"}
]},
)
我收到的文件没有问题,但是taskName
和taskLink
从未到达服务器。
(我尝试过邮递员,没问题)
与此有关的一些问题:
https://elixirforum.com/t/httpoison-post-multipart-with-more-form-than-the-file/4222/4 https://github.com/edgurgel/httpoison/issues/237
答案 0 :(得分:0)
我们有一个多部分列表的工作示例,我们使用它来发送zip文件以及其他属性。与此等效的方法可能对您有用。
[
{"id", to_string(order_id)},
{"file_size", to_string(file_size)},
{"attachment", file, {"form-data", [name: "file", filename: filename]},
[{"Content-Type", "application/zip"}]
}
]