我正在使用woocommerce rest api开发IONIC3应用程序。 GET请求成功运行,但POST,DELETE和PUT请求提供了401错误,代码为{woowoo_rest_cannot_create“,消息:“对不起,您不允许创建资源。}。我没有使用任何外部插件。 下面是我得到的代码和错误:
this.WooCommerce1 = WC({
url: "http://localhost/wordpress",
consumerKey: "ck_b5b82786df6fed9fc6490c42ac03xxxxxx",
consumerSecret: "cs_5448abe010b6dad207f044de4954xxxxxxxxx",
wpAPI: true,
version: 'WC/v2',
//queryStringAuth: true
});
var data = {
email: 'john.doe@example.com',
first_name: 'John',
last_name: 'Doe',
username: 'john.doe',
this.WooCommerce1.postAsync('customers', data).then( (data) => {
console.log(JSON.parse(data.body));
});
错误:
Request URL: http://localhost/wordpress/wp-json/WC/v2/customers?
_method = POST&oauth_consumer_key = ck_b5b82786df6fed9fc6490c42ac03e328b9xxxx&oauth_nonce = YW2dTcwkUjlFprl1IvXSNYfCNkfac8qk&oauth_signature_method = HMAC- SHA256&oauth_timestamp = 1537944726&oauth_version = 1.0&oauth_signature = 2kymrBNtFTe RhI5nGja2cJxn%2FSCCZAbGfROKFxxxMxxx%3D
Request Method: POST
Status Code: 401 Unauthorized
Remote Address: [::1]:80
Referrer Policy: no-referrer-when-downgrade
我还使用以下代码更改了.htaccees文件,但无济于事,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
自上个星期以来,我一直被困在这里,有人可以帮忙吗?