我使用 clj-http.client 发出这样的请求
(http/get "https://www.example.com/bar")
并获得状态为 200 的响应。
但是,当我像这样使用 cljs-http.client 发出相同的请求时:
(go (let [response (<! (http/get (str "https://example.com" "/bar")))]
(prn response)))
我收到状态为 0 的响应,在浏览器中显示它已被 cors 策略阻止。
如果 clj-http.client 请求不是,为什么 cljs-http.client 请求会被 cors 策略阻止?
(defn response [data & [status]]
{:status (or status 200)
:headers {"Content-Type" "application/edn"
"Access-Control-Allow-Headers" "Content-Type"
"Access-Control-Allow-Origin" "*"
"Access-Control-Request-Method" "GET"}
:body (pr-str data)})
我用上面的函数响应包装了我对路由“bar”的响应。