【发布时间】:2015-02-16 00:39:41
【问题描述】:
我尝试从 javascript 客户端向名为 addvenue 的foursquare API 发出POST 调用。
这是 API 端点 documentation link。
但是服务器返回 405 - Method not allowed。这是打电话的 sn-p
var postdata = {'oauth_token':$scope.access_token_foursquare,
'v':'20141217','name':'randomlisting',
'll':'44.3,37.2','m':'foursquare'};
var req = {
method: 'POST',
url: 'https://api.foursquare.com/v2/venues/add',
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
data: postdata
}
$http(req).then(function(response){
console.log(response);
});
以下是上述调用的请求和响应包。
Remote Address:103.245.222.185:443
Request URL:https://api.foursquare.com/v2/venues/add
Request Method:OPTIONS
Status Code:405 Method Not Allowed
**Request Headers**
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, authorization, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:api.foursquare.com
Origin:http://localhost:9000
Referer:http://localhost:9000/foursquare
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
**Response Headers**
Accept-Ranges:bytes
Access-Control-Allow-Origin:*
Connection:Keep-Alive
Content-Length:90
Content-Type:application/json; charset=utf-8
Date:Wed, 17 Dec 2014 12:15:15 GMT
Keep-Alive:timeout=10, max=50
Server:nginx
Tracer-Time:1
Via:1.1 varnish
X-Cache:MISS
X-Cache-Hits:0
X-Served-By:cache-sn87-SIN
我还研究了 CORS 问题。在我的情况下,服务器允许所有来源,如响应标头中所示。我对这个问题感到震惊,无法继续。
任何帮助将不胜感激。 提前致谢。
【问题讨论】:
-
这种问题每天都会出现,也许这会有所帮助:stackoverflow.com/questions/19554414/angularjs-disabling-cors
-
感谢您的即时回复。如您提供的链接中所述,我尝试了以下操作。
angular.module('yourModuleHere') .config(function ($httpProvider) { delete $httpProvider.defaults.headers.common['X-Requested-With']; });仍然存在同样的问题。 -
找到解决办法了吗,请分享
标签: javascript angularjs http-post cors foursquare