大佬教程收集整理的这篇文章主要介绍了Angular 2 http未设置标头,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
var headers = new Headers(); headers.set('Authorization','Bearer xxxxxxxxxxx'); this.http.get('http://localhost:8080/outputEndpoints',{ headers: headers }). map(res => res.text()) .subscribe( data=> console.log(data),error=> console.log("Getting Error") );
有了这个,我期望标题是:
Accept:*/* Accept-Encoding:gzip,deflate,sdch,br Accept-Language:es,ca;q=0.8,en-GB;q=0.6,en;q=0.4,fr;q=0.2 Access-Control-Request-Headers:authorization,content-type Authorization: "Bearer xxxxxxxxxxxx" Access-Control-Request-Method:GET Connection:keep-alive Host:localhost:8080 Origin:http://localhost:3000 Referer:http://localhost:3000/ User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/56.0.2924.87 Safari/537.36
相反,我得到以下内容(没有使用令牌授权):
Accept:*/* Accept-Encoding:gzip,content-type Access-Control-Request-Method:GET Connection:keep-alive Host:localhost:8080 Origin:http://localhost:3000 Referer:http://localhost:3000/ User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/56.0.2924.87 Safari/537.36
编辑:
一般信息是:
Request URL:http://localhost:8080/outputEndpoints Request Method:OPTIONS Status Code:401 Remote Address:[::1]:8080
所以OPTIONS调用失败了.在其他应用程序中,一旦OPTIONS调用被接受,它就会在GET请求中找到设置的身份验证令牌.这意味着由于某种原因OPTION调用它不被接受.
使用CURL或SOAP UI进行调用时,它工作正常,因此我认为它不是CORS的问题.我是对的?
任何想法或指南都会非常有用.
以上是大佬教程为你收集整理的Angular 2 http未设置标头全部内容,希望文章能够帮你解决Angular 2 http未设置标头所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。