2017-05-09 145 views
0

這裏是我的代碼:
這段代碼是用來angularjs但是當我提交了信息錯誤「爲預檢響應具有無效的HTTP狀態代碼405」Foursquare API 405方法不允許?

$scope.listLocation = []; 
$scope.getLocation = function() { 

     var time = Date.now(); 
     return $http({ 
      method: "POST", 
      url: 'https://api.foursquare.com/v2/venues/search?ll=11.5448729,104.8921668&client_id=.....&client_secret=......&v=1494294266811&limit=500&radius=500&intent=browse', 
     }).then(function success(res) { 
      $scope.listLocation = res.data.response.venues 
     }, function error(res) {  

      return res; 
     }); 
    } 

回答

0

它看起來像你只需要改變你的method"POST""GET",如果你只是想檢索數據。

$scope.listLocation = []; 
    $scope.getLocation = function() { 

    var time = Date.now(); 
    return $http({ 
     method: "GET", 
     url: 'https://api.foursquare.com/v2/venues/search?ll=11.5448729,104.8921668&client_id=LP5KESHULNRR3BCNKBD3O1J1FNMWQ3RFRHN34SSLV0GPMQLV&client_secret=ZI5233EL5L5LVJZIVHWKWSCBUCX0HIQ3MUJAXIEYVWQGOJTR&v=1494294266811&limit=500&radius=500&intent=browse', 
    }).then(function success(res) { 
     $scope.listLocation = res.data.response.venues 
    }, function error(res) {  

     return res; 
    }); 
} 

P.s.,那client_secret查詢參數看起來很敏感。

+0

我試過方法GET也。它仍然是相同的 – Kristoff

+0

它必須是除了方法和URL之外的東西。對我來說,下面的工作: '$捲曲-is 「https://api.foursquare.com/v2/venues/search?ll=11.5448729,104.8921668&client_id=LP5KESHULNRR3BCNKBD3O1J1FNMWQ3RFRHN34SSLV0GPMQLV&client_secret=ZI5233EL5L5LVJZIVHWKWSCBUCX0HIQ3MUJAXIEYVWQGOJTR&v=1494294266811&limit=500&radius=500&intent=browse」 | head -n1 HTTP/1.1 200 OK ' –

+0

但是如果我試過通過POSTMAN測試它也可以,我不知道爲什麼 – Kristoff