当POSTMAN工作时,角度POST交叉原点错误

编程入门 行业动态 更新时间:2024-10-24 12:21:53
本文介绍了当POSTMAN工作时,角度POST交叉原点错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试从我的角度登录服务POST:

$ http.post('https:// xyz / login ', { header:{'Content-type':'application / json','Accept':'application / json','signature ':'asd'}

我得到这个错误:

XMLHttpRequest无法加载https:// xyz / login。对预检请求的响应不通过访问控制检查:否Access-Control-因此不允许访问原始'http:// localhost:1337'

我试过这个头文件:

$ httpProvider.defaults.useXDomain = true; delete $ httpProvider .defaults.headersmon ['X-Requested-With'];

/ p>

Access-Control-Allow-Origin:*; Access-Control-Allow-Headers :X-Requested-With; Access-Control-Allow-Methods:GET,POST,PUT,DELETE;

有趣的是,POSTMAN工作。

解决方案

您的请求包含非简单标头内容类型和签名,必须包含在回应的 Access-Control-Allow-Headers 标题。

( Content- type

添加内容类型到<$ c $

POSTMAN不受同源策略的约束,因此它在您的服务器的预检响应中包含一个允许访问控制 - 允许头不需要服务器的CORS支持。

I try to POST from my angular login service:

$http.post('xyz/login', { headers: { 'Content-type': 'application/json', 'Accept': 'application/json', 'signature': 'asd' }

And I get this error:

XMLHttpRequest cannot load xyz/login. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:1337' is therefore not allowed access.

I tried this headers:

$httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headersmon['X-Requested-With'];

And also these:

"Access-Control-Allow-Origin": "*"; "Access-Control-Allow-Headers": "X-Requested-With"; "Access-Control-Allow-Methods": "GET, POST", "PUT", "DELETE";

The interesting thing, is that the POSTMAN works. What shoud I have to do?

Thanks.

解决方案

Your request includes non-simple headers Content-type and signature which must be included in the response's Access-Control-Allow-Headers header.

(Content-type is sometimes a simple header, but only for particular values. application/json is not one of those values, and it causes Content-type to become non-simple.)

Add Content-type to Access-Control-Allow-Headers in your server's preflight response.

POSTMAN is not bound by the same-origin policy, so it does not require CORS support from the server.

更多推荐

当POSTMAN工作时,角度POST交叉原点错误

本文发布于:2023-10-29 07:56:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539145.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原点   角度   错误   工作   POSTMAN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!