Javascript 科尔斯奇怪的行为
我正在使用axios客户端和angular2向特定端点进行RESTFull post 我得到这个CORS错误:Javascript 科尔斯奇怪的行为,javascript,angular,cors,Javascript,Angular,Cors,我正在使用axios客户端和angular2向特定端点进行RESTFull post 我得到这个CORS错误: 加载失败http://localhost:57772/api/deepsee/v1/bi_cube_updated_namespace/Data/KPIExecute: 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://localhost:4200因此,不允许访问。 当我在chrome开发工具网络选项卡中检查飞行前请求时,一切似乎都正
加载失败http://localhost:57772/api/deepsee/v1/bi_cube_updated_namespace/Data/KPIExecute: 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://localhost:4200因此,不允许访问。
当我在chrome开发工具网络选项卡中检查飞行前请求时,一切似乎都正常。“网络”选项卡显示以下内容:
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
听起来您只是在
选项
响应中包含响应标题,而不是发布
响应。您需要在两个响应中都包含它们。如果您的apiurl
不正确,您可能也会看到CORS
问题。确保他们都好,他们都好。我甚至在chome dev network tab.Ok中将reponse paylaod视为json。后端是什么?是的,我正在尝试设置它们。