无法在HTTPoison中设置两个或更多cookie

时间:2015-12-18 09:53:13

标签: cookies elixir

当我尝试设置2个或更多cookie时,我只给出第一个

case HTTPoison.get("https://httpbin.org/cookies", %{}, hackney: [cookie: [{"cookie1", "1"} , {"cookie2", "2"}]]) do

{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
IO.puts body
{_, %HTTPoison.Response{status_code: _, body: _}} ->
# Nothing to do
end
end

页面上的答案:

{
  "cookies": {
    "cookie1": "1"
  }
}

(抱歉最终出现错误,我在这里清理了一个复杂的代码):))

1 个答案:

答案 0 :(得分:3)

我不确定为什么您的示例不起作用,但hackney可以接收二进制格式的Cookie。

case HTTPoison.get("https://httpbin.org/cookies", %{}, hackney: [cookie: "cookie1=111; cookie2=222"]) do
  {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
  IO.puts body
end

性反应的

{
  "cookies": {
    "cookie1": "111",
    "cookie2": "222"
  }
}