2017-03-18 82 views
0
$http.post(main+'/api/getcard/', $.param({number: $scope.searchcard}), {headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'} }) 
     .then(function (response) { 
      if(response.data != 0) 
      { 
       $location.path('/redeem/'+response.data.id); 
       console.log(response.data); 
      } 
     }); 

当我使用此代码我的铬发送:

Request URL:http://cards.mporeda.pl/branch/api/getcard 
Request Method:GET 
Status Code:405 Method Not Allowed 

但是,当我在laravel使用相同的代码本地主机服务:8000我得到:

Request URL:http://localhost:8000/branch/api/getcard/ 
Request Method:POST 
Status Code:200 OK 

我没有任何更多$ http配置,只有请求中的这个头部选项。在请求之前,我在控制台上没有错误,所以我认为我的代码是可以的。我的服务器有什么问题吗?

+0

当您使用'POST'时,您应该使用'data'而不是'param' –

回答

5

代码表示发出请求的URL是:

main+'/api/getcard/' 

的网址你的要求说,你正在使用的是:

Request URL:http://cards.mporeda.pl/branch/api/getcard 

这是最有可能造成

  1. 您向您要发送POST请求的URL发出POST请求
  2. 服务器以301个或302状态和Location头重定向到相同的URL,而不/上月底
  3. 浏览器重定向以下,使一个GET请求

响应如果你回头看看了你的请求列表,你应该看到POST请求。

要解决此问题,您需要查看发出重定向的服务器端代码。

相关问题