在HTTPoison(Elixir)中设置域cookie

时间:2015-12-18 12:07:47

标签: cookies elixir

好的,所以我在Elixir中的新问题是我在创建cookie时无法设置显式域。

在这种情况下:

cubic-bezier(.2,.78,.69,.86);
cubic-bezier(.95,.1,1,.85);

当我创建一个cookie时,它会存储一个像.httpbin.org这样的域名,但出于虚假的原因我需要设置像httpbin.org这样的域值(没有上一个点)。

我也尝试过:

HTTPoison.get("httpbin.org/cookies", [{"User-agent", @userAgent}], hackney: [
            cookie: "cookie1=1 cookie2=2"]  ) do    

但是当然语法要求将域名作为cookie名称,将httpbin.org作为cookie值。

谢谢!

1 个答案:

答案 0 :(得分:1)

您想要在开头删除点的原因是什么?它是可选的,它应该匹配整个域有/无点。

How do browser cookie domains work?

另外,我认为domain属性适用于从HTTP服务器返回的Set-Cookie标头,而不是从客户端请求。 httpbin(https://httpbin.org/cookies/set)返回Set-Cookie标头,但它没有指定域属性(只是Path = /)。它将被浏览器等客户端视为.httpbin.org

iex(25)> response = HTTPoison.get!("https://httpbin.org/cookies/set?k2=v2&k1=v1")
%HTTPoison.Response{body: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<title>Redirecting...</title>\n<h1>Redirecting...</h1>\n<p>You should be redirected automatically to target URL: <a href=\"/cookies\">/cookies</a>.  If not click the link.",
 headers: [{"Server", "nginx"}, {"Date", "Fri, 18 Dec 2015 23:49:46 GMT"},
  {"Content-Type", "text/html; charset=utf-8"}, {"Content-Length", "223"},
  {"Connection", "keep-alive"}, {"Location", "/cookies"},
  {"Set-Cookie", "k2=v2; Path=/"}, {"Set-Cookie", "k1=v1; Path=/"},
  {"Access-Control-Allow-Origin", "*"},
  {"Access-Control-Allow-Credentials", "true"}], status_code: 302}
iex(26)> :hackney.cookies(response.headers)
[{"k1", [{"k1", "v1"}, {"Path", "/"}]}, {"k2", [{"k2", "v2"}, {"Path", "/"}]}]

很抱歉,如果我错过了这一点。