【发布时间】:2019-10-03 05:45:25
【问题描述】:
有人可以帮我写一些代码吗,我正在尝试使用离子原生 HTTP,
但它不工作。访问来自http.post 的响应时,我不断收到错误消息。我得到的错误是:
“HTTPResponse”类型上不存在属性“json”
或
“Promise”类型上不存在“订阅”属性。
当我使用import { Http } from '@angular/HTTP' 时,一切正常,但由于某些原因,有时在设备上@987654323@ 不起作用,这就是我想使用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());
}
}
【问题讨论】:
标签: angular typescript http ionic3