Tag: 鲨鱼

AngularJS $ http,CORS和httpauthentication

因为在AngularJS中使用CORS和httpauthentication可能会非常棘手,所以我编辑了这个问题来分享一个有用的课程。 首先我要感谢igorzg。 他的回答帮了我很多。 该scheme如下:您想通过AngularJS $ http服务将POST请求发送到不同的域。 获取AngularJS和服务器设置时需要注意几件棘手的事情。 首先:在您的应用程序configuration中,您必须允许跨域调用 /** * Cors usage example. * @author Georgi Naumov * gonaumov@gmail.com for contacts and * suggestions. **/ app.config(function($httpProvider) { //Enable cross domain calls $httpProvider.defaults.useXDomain = true; }); 第二:你必须指定withCredentials:true和用户名和密码。 /** * Cors usage example. * @author Georgi Naumov * gonaumov@gmail.com for contacts and * suggestions. **/ $http({ url: […]