带有命名文件的 HTTP POST 多部分
HTTP POST multipart with named file
我需要发送一个(多部分)HTTP 请求,其中包含一个名为的文件。这似乎比我想象的更难实现......我试图找出一种方法来使用 HTTPoison,but I can't get it to use a name other than "file". I've tried using Hackney directly, but there doesn't appear to be an option, and there definitely isn't a test on either of these which shows this functionality. I've also had a look at ibrowse and HTTPotion but can't find anything which seems useful (my Erlang is very limited, mind you). Here is an example 我想做的,使用 Ruby 库 Curb (请注意 Curl::PostField.file 需要一个名称和一个文件路径)。
有这么奇怪的事情吗?还是我在这里遗漏了一些明显的东西...非常感谢任何建议。
谢谢!
如果以后有人遇到这个问题,解决方法如下:
HTTPoison.start
request = HTTPoison.post!(url, {:multipart, [{:file, "path/to/file", { ["form-data"], [name: "\"photo\"", filename: "\"/path/to/file\""]},[]}]}, headers, options)
注意额外的转义引号。
我设法让它与
一起工作
HTTPoison.post!(url, {:multipart, [{"name", "value"}, {:file, path_to_file}]})
在这个 Github issue
的帮助下
我需要发送一个(多部分)HTTP 请求,其中包含一个名为的文件。这似乎比我想象的更难实现......我试图找出一种方法来使用 HTTPoison,but I can't get it to use a name other than "file". I've tried using Hackney directly, but there doesn't appear to be an option, and there definitely isn't a test on either of these which shows this functionality. I've also had a look at ibrowse and HTTPotion but can't find anything which seems useful (my Erlang is very limited, mind you). Here is an example 我想做的,使用 Ruby 库 Curb (请注意 Curl::PostField.file 需要一个名称和一个文件路径)。
有这么奇怪的事情吗?还是我在这里遗漏了一些明显的东西...非常感谢任何建议。
谢谢!
如果以后有人遇到这个问题,解决方法如下:
HTTPoison.start
request = HTTPoison.post!(url, {:multipart, [{:file, "path/to/file", { ["form-data"], [name: "\"photo\"", filename: "\"/path/to/file\""]},[]}]}, headers, options)
注意额外的转义引号。
我设法让它与
一起工作HTTPoison.post!(url, {:multipart, [{"name", "value"}, {:file, path_to_file}]})
在这个 Github issue
的帮助下