跨域请求相关

博客主要介绍了跨域请求,提及使用注解进行配置,给出了 @CrossOrigin 注解示例,其中 allowCredentials=\true\ 可缺省,origins 设为 \http://localhost:9105\。

跨域请求

介绍:跨域请求就是在项目中,前段页面发送的请求,访问其他模块的 资源,而引发的问题
实例:http.get('http://localhost:9107/cart/addGoodsToCartList.do?itemId='
			+ $scope.sku.id +'&num='+$scope.num).success(

1、xml 配置
	在被请求的资源中,Controller 设置
	response.setHeader("Access-Control-Allow-Origin", "http://localhost:9105");
	response.setHeader("Access-Control-Allow-Credentials", "true");
	
Access-Control-Allow-Origin 是 HTML5 中定义的一种解决资源跨域的策略。
他是通过服务器端返回带有 Access-Control-Allow-Origin 标识的 Response header,用来
解决资源的跨域权限问题。
	在被请求的资源中进行配置【在请求路径后 添加 {'withCredentials':true}】
	$scope.addToCart=function(){
$http.get('http://localhost:9107/cart/addGoodsToCartList.do?itemId='
+ $scope.sku.id +'&num='+$scope.num,{'withCredentials':true}).success\

2、使用注解进行配置
@CrossOrigin(origins=“http://localhost:9105”,allowCredentials=“true”)
allowCredentials=“true” 可以缺省

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值