简体   繁体   English

Access-Control-Allow-Headers AngularJS不允许请求标头字段Content-Type

[英]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 . 在此之前,我已经为ImgurMandrillBlogger开源了其中一些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.

相关问题 Safari的XMLHttpRequest(POST)失败,“ Access-Control-Allow-Headers不允许请求标头字段Content-Type” - Safari fails XMLHttpRequest (POST) with ' Request header field Content-Type is not allowed by Access-Control-Allow-Headers' Slack 传入 webhook:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段 Content-type - Slack incoming webhook: Request header field Content-type is not allowed by Access-Control-Allow-Headers in preflight response React.js + PHP/Apache:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段内容类型 - React.js + PHP/Apache: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response XMLHttpRequest 已被 CORS 策略阻止:请求 header 字段内容类型在预检响应中不允许访问控制允许标头 - XMLHttpRequest has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response CI和Angular4:在飞行前响应中,Access-Control-Allow-Headers不允许请求标头字段的内容类型 - CI and Angular4 : Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response 被 CORS 策略阻止:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段内容类型 - blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response 预检响应中的 Access-Control-Allow-Headers 不允许 Angularjs 请求标头字段 Access-Control-Allow-Headers - Angularjs Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers in preflight response 根据 CORS 预检响应中的 header 'Access-Control-Allow-Headers' 不允许使用 'content-type' - ‘content-type’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response 请求标头字段Access-Control-Allow-Headers在预检响应中不允许使用Access-Control-Allow-Headers - Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers in preflight response Access-Control-Allow-Headers 不允许请求头字段 Access-Control-Allow-Headers - Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM