有人能帮我做一些代码吗,我正在尝试使用离子本机HTTP,但它不起作用。在从http.post访问响应时,我会继续获取错误。我所犯的错误是:
属性'json‘在'HTTPResponse’类型中不存在
或
属性“订阅”在“承诺”类型上不存在。
当我使用import { Http } from '@angular/HTTP'时,一切都正常,但由于某些原因,有时在设备上HTTP.post不能工作,所以我想在下面使用import { HTTP } from '@ionic-native/http';,我已经包括了这两个代码,请有人帮助我。
这样做很好:
import { Injectable} from '@angular/core';
import {Http} from '@angular/http';
import 'rxjs/add/operator/map';
import {Auth0Config as Config} from '../config/auth0';
@Injectable()
export class Auth {
URL: String;
constructor(public http: Http) {
this.url = Config.AUTH0_DOMAIN;
}
login(user: String, pass: String) {
let endpoint = "/oauth/token";
let body = {
"client_id": Config.AUTH0_CLIENTID,
"username": user,
"password": pass,
"connection": Config.AUTH0_CONNECTION,
"grant_type": "password"
};
return this.http.post(this.url + endpoint, body).map(res => res.json());
}
getProfile(token: String) {
let endpoint = "/userinfo";
let query = "?access_token=" + token;
return this.http.get(this.url + endpoint + query).map(res => res.json());
}
}不管用
import {Injectable} from '@angular/core';
import {HTTP} from '@ionic-native/http';
import 'rxjs/add/operator/map';
import {Auth0Config as Config} from '../config/auth0';
@Injectable()
export class Auth {
URL: String;
constructor(public http: HTTP) {
this.url = Config.AUTH0_DOMAIN;
}
login(user: String, pass: String) {
let endpoint = "/oauth/token";
let body = {
"client_id": Config.AUTH0_CLIENTID,
"username": user,
"password": pass,
"connection": Config.AUTH0_CONNECTION,
"grant_type": "password"
};
return this.http.post(this.url + endpoint, body, {}).then(res => {
var res = res.json()
});
}
getProfile(token: String) {
let endpoint = "/userinfo";
let query = "?access_token=" + token;
return this.http.get(this.url + endpoint + query, {}, {}) //.map(res => res.json());
}
}发布于 2019-05-16 05:17:41
问题在于:
var res = res.json()角型http retuns Promise<Response>
当本机返回Promise<HTTPResponse>时
用这一行代替它
var res = reshttps://stackoverflow.com/questions/56160219
复制相似问题