отправить запрос получить 401 (неавторизованный) woo rest api - PullRequest
0 голосов
/ 18 сентября 2018

Я использую woo api rest ("woocommerce-api": "1.4.2") в моем приложении ionic 3.когда я отправляю почтовый запрос, я получаю эту ошибку: 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));
        }
    );
  }

, но когда я отправляю почтовый запрос, используя почтальона, он также работаетзапросы работают корректно, у меня проблема только в посте!

1 Ответ

0 голосов
/ 19 сентября 2018

Когда вы пытаетесь вызвать метод post с использованием angular в chrome, он вызовет службу параметров, так что ваш вызов API будет из-за ошибки.используя ссылку ниже, вы можете получить четкое разъяснение.

AngularJS выполняет HTTP-запрос OPTIONS для ресурса с несколькими источниками

Если вы пытаетесь использовать устройство реального времениВаш вызов API будет работать, как брелок, попробуйте в устройстве реального времени.

...