gpt4 book ai didi

wordpress - WooCommerce 休息 API "woocommerce_rest_cannot_create"

转载 作者:行者123 更新时间:2023-12-04 00:06:58 26 4
gpt4 key购买 nike

我正在尝试使用 Postman 将产品发布到 WooCommerce Rest API,以下是使用 Postman 在 Javascript 中生成的代码

var settings = {
"async": true,
"crossDomain": true,
"url": "http://woocommerce.dev/wp-json/wc/v1/products",
"method": "POST",
"headers": {
"content-type": "application/json",
"authorization": "OAuth oauth_consumer_key=\\\"ck_da643d25cb86d32dcf1c4a684ba0fdad4acd67ce\\\",oauth_signature_method=\\\"HMAC-SHA1\\\",oauth_timestamp=\\\"1469615598\\\",oauth_nonce=\\\"oOOqcB\\\",oauth_version=\\\"1.0\\\",oauth_signature=\\\"jf%2FepKymwW9IFlv7fwHFTA3aNs8%3D\\\"",
"cache-control": "no-cache",
"postman-token": "2202e03b-243e-96c5-8e77-fcc8919aedbc"
},
"processData": false,
"data": "{\n \"name\": \"Premium Quality\",\n \"type\": \"simple\",\n \"regular_price\": \"21.99\",\n \"description\": \"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.\",\n \"short_description\": \"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\",\n \"categories\": [\n {\n \"id\": 9\n },\n {\n \"id\": 14\n }\n ],\n \"images\": [\n {\n \"src\": \"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg\",\n \"position\": 0\n },\n {\n \"src\": \"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg\",\n \"position\": 1\n }\n ]\n}"
}

$.ajax(settings).done(function (response) {
console.log(response);
});

作为返回,我收到了状态为 401 未授权

的以下响应
{
"code": "woocommerce_rest_cannot_create",
"message": "Sorry, you are not allowed to create resources.",
"data": {
"status": 401
}
}

而使用相同的凭据,我可以在同一端点使用 GET 方法成功获取数据以获取所有产品

http://woocommerce.dev/wp-json/wc/v1/products

此外,在 WooCommerce 中,我已经为此凭据的用户授予了读/写权限

最佳答案

经过将近2个晚上的研究,它与这个问题有关:https://github.com/WP-API/Basic-Auth/issues/35

修改您的 .htaccess 以使基本身份验证工作,如此注释所示:https://github.com/WP-API/Basic-Auth/issues/35#issuecomment-244001216

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

规则必须是 block 中的第一个重写规则。

关于wordpress - WooCommerce 休息 API "woocommerce_rest_cannot_create",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38610599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com