0
Good morning, I wonder if it is possible to define the ip address when consuming a web service Rest in Ionic 3, where the user could define the address and port to which the api would be. The user would set the ip address on the page , for example "192.168.1" and it would be necessary to pass this value to the previous user , example "rest_usuario = 'http://192.168. 1/Webservice/usuarios'". I tried using session but it doesn’t work, localstorage works, but you need to restart the app again. This ip address is saved to a table in sqlite.
html setting.
<form padding [formGroup]="configuracaoForm" (submit)="Enviar()" novalidate>
<ion-item>
<ion-label>Endereço IP</ion-label>
<ion-input type="text" [(ngModel)]="model.ip" formControlName="ip" placeholder="Endereço IP"></ion-input>
</ion-item>
<br>
configuration.ts
Enviar() {
return this.dbProvider.getDB()
.then((db: SQLiteObject) => {
let sql = 'select * from configuracao where endereco_ip =?',
data = [this.model.ip];
return db.executeSql(sql, data)
.then((data: any) => {
if (data.rows.length > 0) {
let config: any[] = [];
for (var i = 0; i < data.rows.length; i++) {
var configuracao = data.rows.item(i);
config.push(configuracao);
localStorage.setItem("ip", this.model.ip)
Rest.
insereUsuario() {
// this.endereco = window.sessionStorage.getItem('endereco');
return new Promise(resolve => {
this.http.get('http://' + localStorage.getItem("ip") + '/WebService/usuarios').subscribe(data => {
resolve(data);
}, err => {
console.log(err);
});
});
}
Thank you for your help :)
– Caroline Ribeiro
checks if the IP address is correct. 192.168.1 is incomplete. Example of a complete IP: 192.168.0.1
– jraspante
Got it. First you need to set a default IP address or before creating the table and entering the data, you ask the user to put the IP.
– jraspante