HTTPoison不接受此自定义标头

时间:2019-12-07 09:44:48

标签: elixir phoenix-framework

我在下面的curl request中起作用了,但是当我将其翻译成下面时,出现以下错误,此标头有什么问题-我觉得我已经尽一切可能了。

url = "https://content.dropboxapi.com/2/files/download"
header = [ {"Authorization", "Bearer #{token}"}, {"Dropbox-API-Arg", "{\"path\": \"/dropboxtest/image.jpg\"}"} ]
HTTPoison.post(url=url, header=header)

** (ArgumentError) argument error
    :erlang.iolist_to_binary([{"Authorization", "Bearer <removed>"}, {"Dropbox-API-Arg", "{\"path\": \"/dropboxtest/image.jpg\"}"}])
    (hackney) /Users/casey/Dropbox/BOS Sales LLC/backyardmicro/projects/k-9dryers/software/connectk9/deps/hackney/src/hackney_request.erl:348: :hackney_request.handle_body/4
    (hackney) /Users/casey/Dropbox/BOS Sales LLC/backyardmicro/projects/k-9dryers/software/connectk9/deps/hackney/src/hackney_request.erl:83: :hackney_request.perform/2
    (hackney) /Users/casey/Dropbox/BOS Sales LLC/backyardmicro/projects/k-9dryers/software/connectk9/deps/hackney/src/hackney.erl:376: :hackney.send_request/2
    (httpoison) lib/httpoison/base.ex:796: HTTPoison.Base.request/6

1 个答案:

答案 0 :(得分:1)

您要调用的函数是documented here

它的格式为:

HTTPoison.post(url, body, headers \\ [], options \\ []) 

因此,第一个参数应为URL,然后是正文,然后是标题。

在编写HTTPoison.post(url=url, header=header)时,请注意url=urlheader=header对于您要实现的目标并没有真正的意义,只需写一个空的正文即可:

HTTPoison.post(url, "", header)

(作为建议,如果您是我,也将header重命名为headers