0

我在ionic2应用程序中使用来自nmp的crypto和oauth-1.0a。我想访问正确设置为处理身份验证的 WP-API,我使用 Postman 对此进行了测试。

Http.Get 导致以下错误:

{
  "_body": {
    "isTrusted": true
  },
  "status": 0,
  "ok": false,
  "statusText": "",
  "headers": {},
  "type": 3,
  "url": null
}

我作为参数传递给 Http.Get 的生成选项如下:

{“method”:0,“headers”:{“Authorization”:“OAuth oauth_consumer_key=”",
oauth_nonce=“jSZGPwkj4quRGMb0bhBLYKwmc3BGfrQw”, oauth_signature=“x3zseS3XTFBLMsNDLXC4byn2UDI%3D”,
oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1522414816”,
oauth_token="",
oauth_version=“1.0"”},“body”:null,“url”:"",“params”:{“rawParams”:"",“queryEncoder”:{},“paramsMap”:{}},“withCredentials”:null,“responseType”:null}

部分代码:

this.oauth = new OAuth({
consumer: {
key: this.apiconstant.consumerkey,
secret: this.apiconstant.consumersecret
},
signature_method: ‘HMAC-SHA1’,
hash_function: hash_function_sha1,
realm:’’
});
let request_data = {
url: ‘’,
method: ‘GET’
};

let token={
key: this.apiconstant.token,
secret: this.apiconstant.tokensecret
}
//This part doesn’t seem to work
this.authkey = this.oauth.authorize(request_data,token);
this.keyoauth = new URLSearchParams();
for (let param in this.authkey) {
this.keyoauth.set(param, this.authkey[param]);
}

let options = new RequestOptions({
method: ‘GET’,//request_data.method
url: ‘’,
headers: this.oauth.toHeader(this.oauth.authorize(request_data,token)),
search: this.keyoauth
});

this.http.get(’’,options)
.map(res => res.json()).subscribe(data=>{
console.log(‘Resulting data’ + JSON.stringify(data));
},
error=>{
console.log(‘Got error’+JSON.stringify(error));
});

//错误部分执行

我在这里想念什么?我正在安卓设备上测试我的应用程序。如果没有身份验证,我会从 WP-API (Wordpress) 获得所需的结果,也就是说,如果在 WP-API 上禁用了 Oauth。

请帮忙!这是我的第二天。我还应该让你知道我是这些技术的新手,但我能够研究和理解它们是如何工作的。

4

0 回答 0