angularJS $ http.Post不工作:未能加载资源:请求头字段0不受接入控制允许不允许标题 [英] angularJS $http.Post not working: Failed to load resource: Request header field 0 is not allowed by Access-Control-Allow-Headers
问题描述
我使用$ HTTP一些数据发布到我的数据库。
这里是数据库的文档。
我用它在我的终端上和它的作品。
I'm using $http to post some data to my data base. Here is the documentation of the database. I use it on my terminal and it works.
下面是错误信息,我从Safari浏览器的控制台有:
Here's the error message I got from Safari's console:
1)无法加载资源:请求头字段0不受接入控制允许不允许标题。 (似乎是由数据库来感测)
1)Failed to load resource: Request header field 0 is not allowed by Access-Control-Allow-Headers. (seems to be sensed by the database)
2)XMLHtt prequest无法加载的https://beta-api.mongohq.com/mongo/MyDId/myDatabse/collections/myCollection/documents.请求头字段0不受接入控制允许允许标题
2)XMLHttpRequest cannot load https://beta-api.mongohq.com/mongo/MyDId/myDatabse/collections/myCollection/documents. Request header field 0 is not allowed by Access-Control-Allow-Headers.
下面是我的code:
factory.sendUrlTag = function(data){
d = '{"document" : {"url_URL":"53738eef9256a31f4fdf6bf8","tag_Tag":"537375fc9256a31f4fdf6bf3"} }'
return $http({
url: 'https://beta-api.mongohq.com/mongo/MyDId/myDatabse/collections/myCollection/documents',
method: "POST",
data: d,
headers: [
{'Access-Control-Allow-Origin':'*'},
{'Access-Control-Allow-Headers':'Origin, X-Requested-With, Content-Type, Accept'},
{'Content-Type': 'application/json'},
{'Authorization' : 'api-key MyKey'}
]
})
}
return factory;
};
我没有{访问控制允许来源':'*'},
{访问控制允许报头':'原产地,X-要求-着,内容类型,接受},之前,我做了一些研究,我得到了错误,并添加这些后,但它仍然没有工作。
I didn't have " {'Access-Control-Allow-Origin':'*'}, {'Access-Control-Allow-Headers':'Origin, X-Requested-With, Content-Type, Accept'}," before, but I did some research after I got the error and added these. But it's still not working.
我做$ http.get()在我的应用程序相同的数据库和它的作品。
I do $http.get() in my app to the same database and it works.
这件事我发疯....
请帮忙!
谢谢你们! :)
This thing is driving me nuts.... Please help! Thank you all! :)
推荐答案
我找到了一些方法,也许能够得到解决这个问题:
使用这并的这里解决跨起源起源问题。
和这以解决本地主机
I found some way maybe able to get around the issue: Use this and here to get around the cross origin origin issue. And this to get around the localhost
这可能工作。
另一个相对帖子。
这篇关于angularJS $ http.Post不工作:未能加载资源:请求头字段0不受接入控制允许不允许标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!