[英]Request header field Content-Type is not allowed by Access-Control-Allow-Headers AngularJS
I am working on an API module that makes CORS requests to the service endpoint: 我正在研究一个API模块,该模块向服务端点发出CORS请求:
https://github.com/gigablox/angular-blitline-api https://github.com/gigablox/angular-blitline-api
See the demonstration here: 在此处查看演示:
http://plnkr.co/FjnJbHQHG5MM7P0VbtV6 http://plnkr.co/FjnJbHQHG5MM7P0VbtV6
You will notice when the API call is made I receive the following error message: 您会注意到在进行API调用时,我收到以下错误消息:
Request header field Content-Type is not allowed by Access-Control-Allow-Headers
I've open sourced a few of these API modules before for --- Imgur , Mandrill , and Blogger --- but this is the first time I've ever seen this problem using Blitline . 在此之前,我已经为Imgur , Mandrill和Blogger开源了其中一些API模块,但这是我第一次使用Blitline看到此问题。
Is there an issue in my code or does the service provider not like the way the request is being sent to them because of some AngularJS $http
convention? 我的代码中是否存在问题,或者由于某些AngularJS
$http
约定,服务提供商是否不喜欢将请求发送给他们的方式?
I was able to find a related topic however the solution provided did not work. 我能够找到一个相关主题,但是提供的解决方案无效。
delete $httpProvider.defaults.headers.common['X-Requested-With'];
Feel free to try it with that plunker --- I should note I am using 1.1.5 随便尝试一下那个矮子---我应该注意我正在使用1.1.5
Update 更新
Your plnkr worked for me... sort of. 您的plnkr对我有用... I get the following response:
我得到以下回应:
{"results":"Sorry, 'json' key expected in post data. For example { \"json\": \"{...}\" }. Please check the Blitline examples."}
According to the docs : 根据文档 :
A job is a collection of 1 or more functions to be performed on an image.
作业是要在图像上执行的一项或多项功能的集合。 Data submitted to the job api must have a key of "json" and a value that is a string.
提交给作业api的数据必须具有键“ json”和一个字符串值。 The string must contain properly formatted JSON.
该字符串必须包含格式正确的JSON。
You should be submitting your POST in a format like this: 您应该以以下格式提交POST:
angular.module('myApp', ['blitline'])
.config(['$blitlineGlobalProvider', function($blitlineGlobalProvider) {
$blitlineGlobalProvider.options({
json: '{"application_id": "YOUR_ID","version": 2,"src": "http://cdn.blitline.com/filters/boys.jpeg","functions": [{"name": "resize_to_fit","params": {"width": 240,"height": 140},"save": {"image_identifier": "external_sample_1"}}]}'
});
}])
.controller('blitlineTest', ['$scope', '$blitlineJob', function($scope, $blitlineJob) {
var blitlineJob = $blitlineJob.blitlineJob();
blitlineJob.job(function(job) {
console.log(job);
});
}]);
Here is an updated plnkr: http://plnkr.co/edit/qV7sEf?p=preview 这是更新的plnkr: http ://plnkr.co/edit/qV7sEf?p=preview
Bitline has a working example on their site You can see it here: http://www.blitline.com/docs/sample 位线在其网站上有一个有效的示例,您可以在此处查看: http : //www.blitline.com/docs/sample
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.