【问题标题】:Request Forbidden 403 when request made to Square-Connect from localhost从 localhost 向 Square-Connect 发出请求时请求禁止 403
【发布时间】:2019-12-29 05:32:28
【问题描述】:

我正在尝试使用 angularjs 向“https://connect.squareup.com/v2/locations”发出请求,其中调用失败,说 403 FORBIDDEN。

这里是代码示例:

var url = 'https://connect.squareup.com/v2/locations';
        var config = {
            headers: {
                'Authorization': 'Bearer sandbox-sq0atb-JJGltCa375qzAyoQbjPgmg',
                'Accept': 'application/json',
                "X-Testing": "testing"
            }
        };
        $http.get(url, config)
           .then(
               function (response) {
                   console.dir(response);
               },
               function (response) {
                   console.log("failed" + response)
               }
            );

我对上面的示例做了一个小提琴。任何帮助表示赞赏。

http://jsfiddle.net/dx6tdrha/

【问题讨论】:

  • 您正在处理 CORS 问题,它必须通过服务器处理。

标签: angularjs http payment-gateway square-connect


【解决方案1】:

您是否看到此错误:XMLHttpRequest cannot load https://connect.squareup.com/v2/locations. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.?这意味着您无法通过前端 Javascript(如 AngularJS)访问 API,您需要使用不同的实现,如 Node.js、PHP 等。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-31
  • 2016-11-24
  • 2012-02-03
  • 1970-01-01
  • 2023-03-10
相关资源
最近更新 更多