woocommerce rest api put请求中的403错误

时间:2019-01-05 10:41:01

标签: .htaccess ionic3 put woocommerce-rest-api

我正在使用nodeJS和woocommerce作为后端进行Ionic项目。当我尝试使用以下代码修改用户时,出现403禁止错误! (user_id 143存在于我的woocommerce中)

   this.WooCommerce = WC({
      url: "https://mmarket.ir",
      consumerKey: "ck_bd5########################fa",
      consumerSecret: "cs_b9######################c7",
      wpAPI: true,
      version: 'wc/v3'
    });

var data = {
  first_name: 'James'
};

this.WooCommerce.put('customers/143', data, function(err, data, res) {
  console.log(res);
});

结果:

PUT https://mmarket.ir/wp-json/wc/v3/customers/143 403 (Forbidden)
passwordreset.ts:152 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /wp-json/wc/v3/customers/143
on this server.<br />
</p>
</body></html>

我的.htaccess文件内容:

Header add Access-Control-Allow-Origin: "*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Header add Access-Control-Allow-Headers: "Content-Type"

# BEGIN WordPress
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# END WordPress

有什么主意吗?

1 个答案:

答案 0 :(得分:0)

我使用以下代码编辑.htaccess:

<Limit GET POST PUT OPTIONS>
    Require all granted
</Limit>
<LimitExcept GET POST PUT OPTIONS>
    Require all denied
</LimitExcept>

并且403错误在放置请求中消失了。 PUT request 403 Forbidden