【发布时间】:2020-06-18 07:16:18
【问题描述】:
我有一个非常简单的请求,但看起来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
【问题讨论】:
-
我尝试使用
nc -l 9999启动netcat 并向http://localhost:9999发出此请求 - 我可以看到额外的字段。但是如果我向https://postman-echo.com/post提出相同的请求,它似乎没有注意到这些字段。也许它(以及您使用的服务器)不喜欢 Hackney 发送content-length和content-type标头? -
服务器正在使用节点...我认为您是对的,当我使用 axios (node) 发出请求时,一切正常。我将研究 hackney 和 axios 标头之间的区别。谢谢!