我不知道他们用离子3或角4做了什么,但是.
我的问题是,在Android上它可以工作,但是在iOS设备上,我得到了这个错误:
Failed to load resource: Request header field password is not allowed by Access-Control-Allow-Headers这位是来电者:
var optionsWoo = new HttpHeaders()
//.set("Content-Type", "application/x-www-form-urlencoded")
//.set("Content-Type", "application/json")
.set("user", wp_key)
.set("password", wp_sec)
.set("Authorization", "Basic " + window.btoa(wp_key+":"+wp_sec));
this.http.get(site_url + 'wp-json/wc/v2/customers/' + id, {headers: optionsWoo}).toPromise()
.then(usr => {
return this.mergeUser(usr);
}, err => {
console.warn('errorS getUserAndMerge', err);
return Promise.reject(err);
});我创建我的应用程序的第一步是:
import {HTTP} from '@ionic-native/http'; - in app.module.ts
import {Http} from "@angular/http"; - in Provider现在我搬到:
import {HttpClientModule} from "@angular/common/http"; - in app.module.ts
import {HttpClient, HttpHeaders} from "@angular/common/http"; - in Provider并使用这两个包与离子插件:
<plugin name="cordova-plugin-advanced-http" spec="^1.11.0" />httpS身份验证只需在用户/传递API密钥和Api秘密时向头添加即可。对吗??我的意思是,它是从PostMan的工作,它正在运行的安卓!但在iOS上我得到了同样的错误.已经做了两天了..。
离子信息
cli packages: (/usr/local/lib/node_modules)
@ionic/cli-utils : 1.19.1
ionic (Ionic CLI) : 3.19.1全球一揽子计划:
cordova (Cordova CLI) : 7.1.0 本地套餐:
@ionic/app-scripts : 3.1.8
Cordova Platforms : ios 4.5.4
Ionic Framework : ionic-angular 3.9.2系统:
ios-deploy : 1.9.2
ios-sim : 5.0.11
Node : v8.9.3
npm : 5.7.1
OS : macOS Sierra
Xcode : Xcode 9.2 Build version 9C40b package.json
{
"name": "myTitlte",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "5.2.9",
"@angular/compiler": "5.2.9",
"@angular/compiler-cli": "5.2.9",
"@angular/core": "5.2.9",
"@angular/forms": "5.2.9",
"@angular/http": "5.2.9",
"@angular/platform-browser": "5.2.9",
"@angular/platform-browser-dynamic": "5.2.9",
"@ionic-native/app-version": "^4.5.3",
"@ionic-native/camera": "^4.5.3",
"@ionic-native/core": "4.6.0",
"@ionic-native/device": "^4.5.3",
"@ionic-native/device-feedback": "^4.5.3",
"@ionic-native/dialogs": "^4.5.3",
"@ionic-native/http": "^4.6.0",
"@ionic-native/keyboard": "^4.5.3",
"@ionic-native/network": "^4.5.3",
"@ionic-native/splash-screen": "4.6.0",
"@ionic-native/status-bar": "4.6.0",
"@ionic-native/zbar": "^4.5.3",
"@ionic/storage": "2.1.3",
"cordova-ios": "^4.5.4",
"cordova-plugin-advanced-http": "^1.11.0",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-camera": "^4.0.2",
"cordova-plugin-cszbar": "^1.3.4",
"cordova-plugin-device": "^2.0.1",
"cordova-plugin-dialogs": "^2.0.1",
"cordova-plugin-file": "^6.0.1",
"cordova-plugin-ionic-keyboard": "^2.0.5",
"cordova-plugin-ionic-webview": "^1.1.16",
"cordova-plugin-network-information": "^2.0.1",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.1",
"cordova-plugin-velda-devicefeedback": "0.0.2",
"cordova-plugin-whitelist": "^1.3.3",
"ionic-angular": "3.9.2",
"ionic-select-searchable": "^1.0.9",
"ionicons": "3.0.0",
"rxjs": "5.5.7",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.20"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.8",
"typescript": "2.7.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-app-version": {},
"cordova-plugin-camera": {},
"cordova-plugin-cszbar": {},
"cordova-plugin-device": {},
"cordova-plugin-velda-devicefeedback": {},
"cordova-plugin-network-information": {},
"cordova-plugin-dialogs": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-advanced-http": {}
},
"platforms": [
"ios"
]
}
}刚刚更新了一些主要的软件包,比如"@angular/common": "5.0.3",和npm,但是同样的事情.
谢谢!!
发布于 2018-03-28 16:08:20
我通过添加wordpress秘密和键作为查询参数来修正这个问题。
var authQuery = '?username=' + wp_key + '&password=' + wp_sec;
this.http.post(site_url + 'wp-json/wc/v2/customers' + authQuery etc...https://stackoverflow.com/questions/49404347
复制相似问题