You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Buenos dias, estoy trabajando en ionic 5 consumiendo la api de odoo 8 por el protocolo jsonrpc
envio mis solicitudes por un post y obtengo un http failure response for url: https://demo.onreserva.com : unknown 0 cuando pruebo en postman funciona correctamente, aqui esta el codigo de mi servicio codigo:
import { Injectable, Inject } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Headers, RequestOptions, Http } from '@angular/http';
import { HTTPOriginal } from '@ionic-native/http';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
import 'rxjs/Rx';
import { HTTP, HTTPResponse } from '@ionic-native/http/ngx';
import { UtilsService } from './utils.service';
import 'rxjs/add/operator/map';
class Cookies { // cookies doesn't work with Android default browser / Ionic
public sendRequest(url: string, params: Object): Promise {
let body = this.buildRequest(url, params);
/*let options = new RequestOptions({
headers: this.headers
});
Buenos dias, estoy trabajando en ionic 5 consumiendo la api de odoo 8 por el protocolo jsonrpc
envio mis solicitudes por un post y obtengo un http failure response for url: https://demo.onreserva.com : unknown 0 cuando pruebo en postman funciona correctamente, aqui esta el codigo de mi servicio codigo:
import { Injectable, Inject } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Headers, RequestOptions, Http } from '@angular/http';
import { HTTPOriginal } from '@ionic-native/http';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
import 'rxjs/Rx';
import { HTTP, HTTPResponse } from '@ionic-native/http/ngx';
import { UtilsService } from './utils.service';
import 'rxjs/add/operator/map';
class Cookies { // cookies doesn't work with Android default browser / Ionic
}
@Injectable({
providedIn: 'root'
})
export class OdoojsonrpcService {
private odoo_server: string;
private http_auth: string;
private cookies: Cookies;
private uniq_id_counter: number = 0;
private shouldManageSessionId: boolean = false; // try without first
private context: Object = JSON.parse(localStorage.getItem("user_context")) || {"lang": "en_US"};
private headers: HttpHeaders;
private jsonRpcID: number = 0;
private list = "/web/database/list";
private get_list = "/web/database/get_list";
private jsonrpc = "/jsonrpc";
constructor(private http: HTTP, private util: UtilsService, @Inject(HttpClient) private https: HttpClient) {
this.cookies = new Cookies();
this.https = https;
}
private buildRequest(url: string, params: any) {
this.uniq_id_counter += 1;
this.jsonRpcID += 1;
if (this.shouldManageSessionId) {
params.session_id = this.cookies.get_sessionId();
}
}
private handleOdooErrors(response: any) {
if (!response.error) {
return response.result;
}
}
private handleHttpErrors(error: any) {
return Promise.reject(error.message || error);
}
public sendRequest(url: string, params: Object): Promise {
let body = this.buildRequest(url, params);
/*let options = new RequestOptions({
headers: this.headers
});
}
public init(configs: any) {
this.odoo_server = configs.odoo_server;
this.http_auth = configs.http_auth || null;
}
public setOdooServer(odoo_server: string) {
this.odoo_server = odoo_server;
}
public setHttpAuth(http_auth: string) {
this.http_auth = http_auth;
}
public getServerInfo() {
return this.sendRequest("/web/webclient/version_info", {});
}
public getSessionInfo() {
return this.sendRequest("/web/session/get_session_info", {});
}
public login(db: string, login: string, password: string) {
let params = {
db : db,
login : login,
password : password,
context: {}
};
let $this = this;
return this.sendRequest("/web/session/authenticate", params).then((result: any)=> {
//let res = JSON.stringify(result);
//let response = JSON.parse(res)["result"]
if (!result.uid) {
$this.cookies.delete_sessionId();
return Promise.reject({
title: "wrong_login",
message: "Username and password don't match",
fullTrace: result
});
}
$this.context = result.user_context;
localStorage.setItem("user_context", JSON.stringify($this.context));
$this.cookies.set_sessionId(result.session_id);
return result;
});
}
}
aqui esta la llamada desde mi componente
login(){
console.log(this.db)
console.log(this.email)
console.log(this.password)
console.log(this.util.getCompany())
this.odooRpc.login(this.db, this.email, this.password).then((result:any)=>{
this.presentToast(JSON.stringify(result));
this.navCtrl.navigateForward('/dashboard');
}).catch((error)=>{
this.presentToast(error);
})
}
espero su ayuda llevo varias semanas en este tema probe con http ionic-native y nada
The text was updated successfully, but these errors were encountered: