Woocommerce api CORS error



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

我遵循了此设置,如下所示:

{
"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.

更改 网址:"https://mystore.net/index.php" 至 网址:"https://mystore.net">

"proxyUrl": "https://mystore.net/index.php/wp-json/wc/v2" TO "proxyUrl": "https://mystore.net/wc-api/v2">

最新更新