最近工作中发现,使用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. Swift中WebView的应用

    WebView控件是做网络应用开发中使用最多的控件,直接在WebView内部指定一个网页地址就可以访问网页了,同时也可以实现UIWebViewDelegate协议实现相应的方法去控制内容的加载和处理. ...

  2. magento开发中文手册

    Magento开发 第一章 手册简介Introduction 对一个开发人员来说,电子商务开发也许是现今最具创造性的工作.在这个瞬息万变的网络世界,为了保持始终领先竞争对手一步,无论是对你自己还是你的 ...

  3. stm32 定时器TIM时钟步骤

    1)TIM3 时钟使能 . RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIMx, ENABLE); //时钟使能 2) 初始化定时器参数,设置自动重装值, 分频系数, ...

  4. CodeForces - 457C:Elections(三分)

    You are running for a governor in a small city in Russia. You ran some polls and did some research, ...

  5. ConfigUtil读取配置文件

    package utils; import java.util.ResourceBundle; public class ConfigUtil { private static ResourceBun ...

  6. layer关闭弹出层总结

    //关闭方法1 layer提供了5种层类型.可传入的值有:0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层). 若你采用layer.open({type: 1})方式调用, ...

  7. Microsoft - Find the K closest points to the origin in a 2D plane

    Find the K closest points to the origin in a 2D plane, given an array containing N points. 用 max hea ...

  8. hasura graphql server event trigger 试用

    hasura graphql server 是一个很不错的graphql 引擎,当前版本已经支持event triiger 了 使用此功能我们可以方便的集成webhook功能,实现灵活,稳定,快捷的消 ...

  9. spring 核心思想:AOP 理解

    什么是AOP? AOP概念介绍 所谓AOP,即Aspect orientied program,就是面向方面(切面)的编程. 面向切面编程Aspect-Orlented-Programming,即AO ...

  10. CentOS6.8 x64+Nginx1.3.8/Apache-httpd 2.4.3+PHP5.4.8(php-fpm)+MySQL5.5.28+CoreSeek4.1源码编译安装

    系统为CentOS6.8 x64服务器版精简安装. 准备工作 部署安装目录 /usr/local/* /var/lib/* /var/lib64/* 下载源文件 #cd /usr/local/src ...