【发布时间】:2019-05-06 04:13:12
【问题描述】:
我正在尝试在 Elixir Phoenix 中使用 HTTPoison 转换 CURL 请求。 当我运行 CURL 请求推荐时,它工作正常。当我尝试使用 HTTPoison 时出现“415 Unsupported media type”错误。
Phoenix/Elixir - cURL works, but HTTPoison fails
这是我的 CURL 请求
curl -u "user:password" -i -H "Accept:application/json" -X POST -d
"amount=100&method=0&type=bank&receiver=CCC&info1=hello"
http://00.000.000.00:8080/services/id/999999111999/calculate
这是我的 Httpoison 请求
url = "myurl"
orderid = "myorderid"
headers = ["Accept", "application/json"]
request_body = '{"type" : "bank",
"method" : 0,
"amount" : #{amount},
"receiver" : "CCC"
"info1" : #{orderid}}'
dicoba = HTTPoison.post(url, headers, request_body, hackney: [basic_auth: {"#{user}", "#password"}]) |> IO.inspect
【问题讨论】:
-
我怀疑
HTTPoison在request_body参数中支持lists,而你的确实是一个列表而不是字符串。 Elixir 中的单引号并不符合您的预期。请改用~ssigil。
标签: curl elixir phoenix httpoison