【问题标题】:AngularJS weird CORS issues depending on method calling POSTAngularJS奇怪的CORS问题取决于调用POST的方法
【发布时间】:2014-04-23 22:17:39
【问题描述】:

很简单!为什么这不起作用:

      $http.post(apiUrl + '/some/url/blah', {params: data, withCredentials: true})
      .then(function(result){
          //success!
      });

然而这确实!

      $http({
          method: 'POST',
          withCredentials: true,
          url: apiUrl + '/some/url/blah',
          params: data
      })
      .success(function(data, status, headers, config) {
          //success!!
      });

我在第一个示例中收到 401 未经授权!第二个就像一个魅力..

【问题讨论】:

  • params: data 用于 GET,对于 POST,您应该使用 data: data

标签: angularjs angularjs-http


【解决方案1】:

当使用 $http.post 简写时,第二个参数是数据。试试这个:

$http.post(apiUrl + '/some/url/blah', {}, {params: data, withCredentials: true})
  .then(function(result){
      //success!
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 2014-02-20
    • 1970-01-01
    • 2016-09-03
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多