最近工作中发现,使用angular $http跨域的时候,虽然后台已经配置了跨域允许,但是还是报错。

查资料发现,angular $http 的request的请求头中,默认有:

Access-Control-Request-Headers:x-requested-with  
 
而jQuery/fetch 等其他的ajax请求没有这个默认设置,解决办法有2种。
 
1.在client 端,angular里面设置,例如:
const app = angular.module(config.name)
.config(function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
})

2.或者在server端设置跨域的时候:

res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');

X-Requested-With的更多相关文章

  1. CentOS:ECDSA host key "ip地址" for has changed and you have requested strict checking(转)

    原文地址:http://blog.csdn.net/ausboyue/article/details/52775281 Linux SSH命令错误:ECDSA host key "ip地址& ...

  2. git clone出现的error: The requested URL returned error: 401 Unauthorized

    error: The requested URL returned error: 401 Unauthorized while accessing https://git.oschina.net/.. ...

  3. 共享文件夹:The user has not been granted the requested logon type at this computer

    场景重现 今天做一个项目测试,要用到虚拟机,于是在虚拟机(XP 32)上新建了一个共享的文件夹.然后我在Win7 机器上访问它得到如下的error 消息:

  4. 解决PKIX:unable to find valid certification path to requested target 的问题

    这两天在twitter服务器上忽然遇到这样的异常: e: sun.security.validator.ValidatorException: PKIX path building failed: s ...

  5. ORA-12520: TNS:listener could not find available handler for requested type of server

    当你碰到ORA-12520错误时,如下所示: 英文错误提示: ORA-12520: TNS:listener could not find available handler for requeste ...

  6. com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address: bind

    在发布 web service 时报错: Endpoint.publish(publishAddress, hl7MessageReveiver); com.sun.xml.internal.ws.s ...

  7. asp.net mvc 5 web api 关于Requested resource does not support options 问题

    1.用visual studio 2015 建立一个 web api 应用程序.记住这是一个 web api 应用. 2.新建一个web api . 3.用C#访问,代码如下:[没有问题,返回正确] ...

  8. js跨域访问,No 'Access-Control-Allow-Origin' header is present on the requested resource

    js跨域访问提示错误:XMLHttpRequest cannot load http://...... No 'Access-Control-Allow-Origin' header is prese ...

  9. 解决 java 使用ssl过程中出现"PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

    今天,封装HttpClient使用ssl时报一下错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExc ...

  10. oracle异常:ORA-01422: exact fetch returns more than requested

    ORA-01422: exact fetch returns more than requested 神奇的错误,困扰了我一个下午. 问题描述:明明只有一行记录,结果是报了多条记录的错误.令我百思不得 ...

随机推荐

  1. PLsql登录数据库提示密码即将过期-

    小哥询问,PL*SQL用户登录后弹出警告:咋整? ORA-28002:the password will expire within 7 days密码在7天内将到期 do you wish to ch ...

  2. 连接APB1和APB2的设备有哪些

    在STM32中 APB1(低速外设)上的设备有:电源接口.备份接口.CAN.USB.I2C1.I2C2.UART2.UART3.SPI2.窗口看门狗.Timer2.Timer3.Timer4 . AP ...

  3. PHPEmailer使用简介(以qq邮箱为例)

    1.从网上下载PHPEmailer: 2.确保PHP环境支持sockets扩展,还要开启openssl,如下图: 3.配置QQ邮箱 1.开启SMTP服务 2.验证密保 3.获取授权码(这个就是IMAP ...

  4. 2018-2019-2 20165212 《网络对抗技术》Exp3 免杀原理与实践

    2018-2019-2 20165212 <网络对抗技术>Exp3 免杀原理与实践 一.实验内容 正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion ...

  5. excel导出: mac safari对application/x-msdownload的支持不佳

    https://blog.csdn.net/lizeyang/article/details/8982155?locationNum=3&fps=1 http://tool.oschina.n ...

  6. getParameter、getParameterValues、getParameterMap用法详解

    首先request中的参数parameter是一个map表,如下例 map={username=[xxx],password=[xxx],hobby=[eat,drink]} (1)当调用getPar ...

  7. day7 python学习

    今日内容# 枚举 此代码可以用于对有一定值的列表进行按带序列号的方式打印出来 lis=['手机','电脑','潜艇','手表'] for index,i in enumerate(lis,1): pr ...

  8. Linux 'XXXXXX' "is not in the sudoers file. This incident will be reported" 解决方法

    添加方法如下: 1.进入root模式su -  注意:su和-之间有空格输入当前用户的密码 2.添加写权限chmod u+w /etc/sudoers 3.将自己加入到sudoers中 gedit / ...

  9. Codelf 变量取名

    Codelf 变量取名 可以看到别的变量是怎么命名的,站在巨人的肩膀上.

  10. tyvj1061Mobile Service

    题目:http://www.joyoi.cn/problem/tyvj-1061 dp.枚举三个人现在的位置. 1.重点:当前必有一人正处在查询点上!于是省掉一维. 2.转移方程枚举上一阶段的 j 和 ...