【问题标题】:Woocommerce api CORS errorWoocommerce api CORS 错误
【发布时间】:2018-11-02 22:29:01
【问题描述】:

当我使用 woocommerce api 从我的 ionic 移动应用程序向我的 woocommerce 商店发送请求时收到 CROS 错误。

我按照this 设置,如下:

{
  "name": "IonicApp",
  "app_id": "09309832",
  "type": "ionic-angular",
  "integrations": {
    "cordova": {}
  },
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "https://mystore.net/index.php/wp-json/wc/v2"
    }
  ]
}

这是数据请求:

this.WooCommerce = WC({
  url: "https://mystore.net/index.php",
  consumerKey: CONSUMER_KEY,
  consumerSecret: CONSUMER_SECRET,
  wpAPI: true,
  version: 'wc/v2'
});

this.WooCommerce.getAsync(`products/categories`).then((data) => {
  console.log(JSON.parse(data));
}, (err) => {
  console.log(err)
});

这是我得到的错误:

Failed to load https://mystore.net/index.php/wp-json/wc/v2/products/categories: Redirect from 'https://mystore.net/index.php/wp-json/wc/v2/products/categories' to 'https://mystore.net/NeLVZ/index.php/wp-json/wc/v2/products?categories' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

【问题讨论】:

  • 你还有这个问题还是解决了?
  • @Omar 我没有解决它...我只是用一个实际的手机进行测试
  • 那么它运行良好还是你仍然有同样的问题
  • 我也有这个问题

标签: wordpress typescript woocommerce ionic3 woocommerce-rest-api


【解决方案1】:

改变 网址:“https://mystore.net/index.php”到网址:“https://mystore.net

“proxyUrl”:“https://mystore.net/index.php/wp-json/wc/v2”到“proxyUrl”:“https://mystore.net/wc-api/v2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 2016-01-02
    • 2021-08-06
    • 2017-04-26
    • 2018-10-09
    • 1970-01-01
    • 2017-05-04
    相关资源
    最近更新 更多