我的应用程序有问题,在手机上我只能登录,而无法从数据库中获取数据。
如果从浏览器运行该应用程序,则可以登录并从数据库中获取数据。
我不知道会发生什么,我检查了所有内容,但没有发现可能是错误的。
从中调用服务的功能:
import { Component } from '@angular/core';
import { NavController, MenuController } from 'ionic-angular';
import { ServiceRestProvider } from '../../providers/service-rest/service-rest';
import { LoadingController } from 'ionic-angular';
import { AlertController, Platform } from "ionic-angular";
@Component({
selector: 'page-coperativa_resumen',
templateUrl: 'coperativa_resumen.html'
})
export class ResumenCooperativaPage {
loading: any;
resumen: any;
constructor(public navCtrl: NavController,
private menuCtrl: MenuController,
public service: ServiceRestProvider,
public loadingController: LoadingController,
private alertCtrl: AlertController) {
this.getResumen2();
}
getResumen2() {
this.loading = this.loadingController.create({ content: "Buscando información ,espere por favor ResumenMovimientos2..." });
this.loading.present();
this.loading.dismissAll();
console.log("Ejecutando getResumen2");
this.service.getResumenMovimientos2()
.subscribe(data => {
if (data.error) {
//this.loading.dismissAll();
// manejo de errores
this.alertCtrl.create({
title: "Error",
subTitle: 'Mensajes: ' + data.error.tostring(),
buttons: ["OK"]
}).present();
} else {
//this.loading.dismissAll();
//this.navCtrl.pop();
this.resumen = data;
}
});
}
}
我的服务:
import { HttpClient,HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AlertController, Platform } from "ionic-angular";
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
import { Observable } from 'rxjs/observable';
import * as jwt_decode from "jwt-decode";
import { HttpHeaders } from '@angular/common/http';
import { Storage } from '@ionic/storage';
@Injectable()
export class ServiceRestProvider {
// Token: any;
token_full: any;
constructor(public http: HttpClient,
private alertCtrl: AlertController,
private platform: Platform,
private storage: Storage) {
console.log('Entrando a ServiceRestProvider Provider y cargar storage');
this.cargar_storage();
}
public activo(): boolean {
if (this.token_full != "") {
console.log("true");
return true;
} else {
console.log("false");
return false;
}
}
ingresar(codigo: string, usuario: string, contrasena: string) {
const body = JSON.stringify({
Codigo: codigo,
Usuario: usuario,
Password: contrasena
});
const headers = new HttpHeaders().set('Access-Control-Allow-Origin', '*')
.set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT')
.set('Accept', 'application/json')
.set('Content-Type', 'application/json; charset=utf-8');
return this.http.post('http://intsdfca2:84/api/Login', body, { headers: headers})
.map((resp: any) => {
let jwt = jwt_decode(resp);
console.log(jwt);
let jwt_json1 = JSON.parse(resp);
this.token_full = jwt_json1["token"];
if (resp.error) {
this.alertCtrl.create({
title: "Error al iniciar",
subTitle: jwt['Apellidos'],
buttons: ["OK"]
}).present();
} else {
//console.log("No hubo error al cargar");
// this.Token = jwt['Token'];
this.token_full = jwt_json1["token"];
this.guardar_storage();
}
}, err => {
console.log(err);
}
);
}
private guardar_storage() {
if (this.platform.is("cordova")) {
this.storage.set('Token_Full', this.token_full);
} else {
if (this.token_full != "") {
localStorage.setItem("Token_Full", this.token_full);
} else {
localStorage.removeItem("Token_Full");
}
}
}
cargar_storage() {
let promesa = new Promise((resolve, reject) => {
if (this.platform.is("cordova")) {
this.storage.ready()
.then(() => {
this.storage.get("Token_Full")
.then(Token => {
console.log(Token);
if (Token != "") {
this.token_full = Token;
}
})
})
} else {
if (localStorage.getItem("Token_Full") !="") {
this.token_full = localStorage.getItem("Token_Full");
}
resolve();
}
});
return promesa;
}
getNovedades(FechaInicial: any, FechaFinal: any) {
this.alertCtrl.create({
title: "Token a enviar",
subTitle: 'Mensajes: ' + localStorage.getItem("Token_Full").toString(),
buttons: ["OK"]
}).present();
const header = new HttpHeaders().set('Access-Control-Allow-Origin', '*')
.set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT')
.set('Accept', 'application/json')
.set('Content-Type', 'application/json; charset=utf-8')
.set('Authorization', localStorage.getItem("Token_Full").toString())
.set('Authorization', 'Bearer ' + localStorage.getItem("Token_Full").toString());
return new Promise(resolve => {
this.http.get('http://intsdfca2:84/api/EstadoDeCuenta' + '/12122017/12122018', { headers: header }).subscribe(data => {
resolve(data);
}, err => {
console.log(err);
});
});
}
getResumenMovimientos2() {
this.alertCtrl.create({
title: "Token a enviar",
subTitle: 'Mensajes: ' + localStorage.getItem("Token_Full").toString(),
buttons: ["OK"]
}).present();
const header = new HttpHeaders().set('Access-Control-Allow-Origin', '*')
.set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT')
.set('Accept', 'application/json')
.set('Content-Type', 'application/json; charset=utf-8')
.set('Authorization', localStorage.getItem("Token_Full").toString())
.set('Authorization', 'Bearer ' + localStorage.getItem("Token_Full").toString());
return this.http.get('http://intsdfca2:84/api/EstadoDeCuenta', { headers: header})
.map((response) => {
return response;
}).catch(this.handleError);;
}
public handleError(error: HttpErrorResponse) {
return Observable.throw(`Something bad happened; please try again later. error Info: ${error.error.message}`);
}
Cerrar_Sesion() {
this.token_full = null;
this.guardar_storage();
}
}
浏览器中应用程序的图像: 1
该应用在手机中的图片: 2
非常感谢您的帮助。
答案 0 :(得分:0)
使用离子本机http:
只需确保您使用的是离子本机http,如果您使用的是角度HTTP,就会在ios / android设备中造成问题。
EX:
f = lambda x : int(x[0]) * 10000 + int(x[1]) * 100 + int(x[2])
train_df['intday'] = train_df['day'].apply([f(x) for x in train_df['day'].str.split('-')])