发出请求获得401(未经授权)woo rest api

问题描述 投票:0回答:1

我在我的离子3应用程序中使用了woo api rest(“woocommerce-api”:“1.4.2”)。当我发送一个帖子请求时,我收到此错误:enter image description here

代码:

  signUp() {
    let customerData = {
      "email": this.newUser.email,
      "first_name": this.newUser.first_name,
      "last_name": this.newUser.last_name,
      "username": this.newUser.username,
      "billing": {
        "first_name": this.newUser.first_name,
        "last_name": this.newUser.last_name,
        "company": "",
        "address_1": this.newUser.billing_address.address_1,
        "address_2": this.newUser.billing_address.address_2,
        "city": this.newUser.billing_address.city,
        "state": this.newUser.billing_address.state,
        "postcode": this.newUser.billing_address.postcode,
        "country": this.newUser.billing_address.country,
        "email": this.newUser.email,
        "phone": this.newUser.billing_address.phone
      },
      "shipping": {
        "first_name": this.newUser.first_name,
        "last_name": this.newUser.last_name,
        "company": "",
        "address_1": this.newUser.shipping_address.address_1,
        "address_2": this.newUser.shipping_address.address_2,
        "city": this.newUser.shipping_address.city,
        "state": this.newUser.shipping_address.state,
        "postcode": this.newUser.shipping_address.postcode,
        "country": this.newUser.shipping_address.country
      }
    };
    if (this.billing_shipping_same) {
      customerData.shipping = customerData.billing;
    }
    this.WooCommerce.postAsync("customers",customerData).then(
        (data)=>{
            console.log(JSON.parse(data.body));
        }
    );
  }

但是当我使用邮递员发送邮件请求时,它的工作也可以正常工作,我的问题只在帖子中!

angular ionic-framework ionic3 angular5 woocommerce-rest-api
1个回答
0
投票

当您尝试使用chrome in chrome进行post方法调用时,它将调用选项服务,以便您的api调用将通过错误。使用查找以下链接,您可以得到明确的澄清。

AngularJS performs an OPTIONS HTTP request for a cross-origin resource

如果您尝试使用实时设备您的api呼叫将像魅力一样在实时设备中尝试。

© www.soinside.com 2019 - 2024. All rights reserved.