榆树:http.post csrf

Elm: http.post csrf

我们如何让 http.post 在请求中设置 X-CSRFToken header?
token取自后台设置的csrftokencookie
我们需要使用 http.send 吗?

如果您查看源代码 (https://github.com/evancz/elm-http/blob/3.0.1/src/Http.elm),post 是 hard-coded 空(即 [])http header。 所以如果你想要自定义 header, post 不起作用,您必须改用 send

您可能要考虑的其他解决方案是 对所有 http 调用执行 CSRF 令牌, 喜欢 this Whosebug 答案建议。