CORS奇怪的行为 [英] CORS Strange behaviour

查看:55
本文介绍了CORS奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有angular2的axios客户端向特定端点进行RESTFull发布.

I am using axios client with angular2 to make a RESTFull post to a specific endpoint.

我收到此CORS错误:

I get this CORS error:

Failed to load http://localhost:57772/api/deepsee/v1/bi_cube_updated_namespace/Data/KPIExecute: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

当我在chrome开发工具网络标签中检查我的飞行前请求时,一切似乎都井然有序.网络标签显示如下:

When I check my preflight request in the chrome dev tools network tab everything seems to be in order. The network tab shows this:

Request URL:http://localhost:57772/api/deepsee/v1/bi_cube_updated_namespace/Data/KPIExecute
Request Method:OPTIONS
Status Code:200 OK
Remote Address:[::1]:57772
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
ACCESS-CONTROL-ALLOW-CREDENTIALS:true
ACCESS-CONTROL-ALLOW-HEADERS:authorization,content-type
ACCESS-CONTROL-ALLOW-METHODS:POST
ACCESS-CONTROL-ALLOW-ORIGIN:http://localhost:4200
ALLOW:POST,OPTIONS

这是实际的帖子:

 Request URL:http://localhost:57772/api/deepsee/v1/bi_cube_updated_namespace/Data/KPIExecute
Request Method:POST
Status Code:200 OK
Remote Address:[::1]:57772
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
CACHE-CONTROL:no-cache
Connection:Keep-Alive
CONTENT-LENGTH:179
Content-Type:application/json; charset=utf-8
Date:Tue, 14 Nov 2017 12:53:46 GMT
EXPIRES:Thu, 29 Oct 1998 17:04:19 GMT
Keep-Alive:timeout=120
PRAGMA:no-cache
Server:Apache

推荐答案

听起来您只在OPTIONS响应中包含响应标头,而不在POST响应中包含响应标头.您需要在两个回复中都包含它们.

It sounds like you're only including the response headers in the OPTIONS response, not the POST response. You need to include them in both responses.

这篇关于CORS奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆