Js_of_ocaml - 获取 cookie 时出错

Js_of_ocaml - Error when get cookie

我是 XmlHttpRequest 以便发出 http 请求并且我想获取 cookie。获取cookie的代码:

let http_post url =
  XmlHttpRequest.perform_raw_url
    ~post_args:[("login", `String (Js.string "foo"));
                ("password", `String (Js.string "bar"))]
    url >>= fun r -> 
  let code = r.XmlHttpRequest.code in
  let msg = r.XmlHttpRequest.content in
  let cookie = match r.XmlHttpRequest.headers "Set-Cookie" with
  | None -> "Empty Cookie"
  | Some s -> s in 
  if code = 0 || code = 200
  then Lwt.return (msg,cookie)

let make_test_request id =
  let button = get_element_by_id id in
  button##onclick <- (Html.handler (fun _ ->
      http_post "www.website.com" >>=
      (fun (msg,cookie) ->
         Printf.printf "cookie = %s\n" cookie;
         Html.document##cookie <- Js.string cookie;
         Printf.printf "s = %s\n" msg;
         Lwt.return());
      Js._true))

Cookie 应该在 header 中,但我收到此错误:Refused to get unsafe header "Set-Cookie"

这是我获取 cookie 错误的方式还是我的网络浏览器有问题(我使用的是 chromium)?

http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method

client . getResponseHeader(header) Returns the header field value from the response of which the field name matches header, unless the field name is Set-Cookie or Set-Cookie2.

答案在