[英]post request get 401 (Unauthorized) woo rest api
我在Ionic 3應用程序中使用woo api rest(“ woocommerce-api”:“ 1.4.2”)。 當我發送發布請求時,出現此錯誤:
代碼:
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));
}
);
}
但是,當我使用郵遞員發送發帖請求時,它也可以正常工作,只有發帖才有問題!
當您嘗試使用chrome中的angular進行post方法調用時,它將調用options服務,以便您的api調用會出錯。 使用以下鏈接,您可以得到清晰的說明。
AngularJS對跨域資源執行OPTIONS HTTP請求
如果您嘗試使用實時設備,您的api調用將像超級按鈕一樣工作,請在實時設備中嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.