How connect odoo (xmlrpc) with ionic running over ios?


#1

down vote
favorite
I am working with ionic 3, I did an app to consume web services from odoo, for this I used a npm package: odoo-xmlrpc.

it work fine with android, but when I simulate for iPhone, it can’t connect with the server. I tried a manual connection, but it wasn’t worked, it show an XHR error, but no show exactly the error.

I used a sniffer(charles) to show me http packages and I get some information. it try to connect using OPTIONS Method, but the server request is 404 not FOUND.

you can see all my code here: https://github.com/jose1914luis/rusia

my configurations:

ionic info:

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 7.1.0 

local packages:

    @ionic/app-scripts : 3.1.6
    Cordova Platforms  : ios 4.5.4
    Ionic Framework    : ionic-angular 3.9.2

System:

    ios-deploy : 1.9.0 
    ios-sim    : 5.0.13 
    Node       : v9.3.0
    npm        : 5.6.0 
    OS         : macOS Sierra
    Xcode      : Xcode 8.2.1 Build version 8C1002 

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

Ionic Code:

import { Component, enableProdMode } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http'
import 'rxjs/Rx';
import 'rxjs/add/operator/map';

import xmlrpc from 'xmlrpc';
import url from 'url';

import * as Odoo from 'odoo-xmlrpc'

enableProdMode();
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  msg = '';
  config = {url:'http://moscutourgratis.com', 
  		port:'8069', 
  		db:'Tour_Gratis_Rusia',
  		username:'xxxx',
  		password:'xxxx'};

  constructor(public navCtrl: NavController, public http: Http) {

  	this.cargar();
  }

  cargar(){
  	var self = this;
  	var odoo = new Odoo(self.config);
  	
    //Fail method with odoo-xmlrpc
  	odoo.connect(function(err){
  		if(err){
  			self.msg += JSON.stringify(err);
  			console.log(JSON.stringify(err));
  			return JSON.stringify(err);
  		}
  		self.msg += 'entro';
  	});

    //manual connection Fail show XHR Error
    this.connect(function(err){
    	self.msg += 'error interno' + JSON.stringify(err);
    });
  }
  

    connect(callback){
    	
    	var urlparts = url.parse(this.config.url);
	    var host = urlparts.hostname;
	    var port = this.config.port || urlparts.port;
	    var db = this.config.db;
	    var username = this.config.username;
	    var password = this.config.password;
	    var secure = true;
	    if(urlparts.protocol !== 'https:') {
	      secure = false
	    }
	    var uid = 0;
        var clientOptions = {
            host: host,
            port: port,
            path: '/xmlrpc/2/common'
        }
        var client;
        if(secure == false) {
          client = xmlrpc.createClient(clientOptions);
          console.log("client normal")
        }
        else {
          client = xmlrpc.createSecureClient(clientOptions);
          console.log(clientOptions)
          console.log("client sécurisé sur le port " + port)
        }
        var params = [];
        params.push(db);
        params.push(username);
        params.push(password);
        params.push({});
        client.methodCall('authenticate', params, function(error, value) {
            if(error){
                console.log('HOLA MUNDO ERROR DE MIERDA' + error);
              return callback(error, null)
            }
            uid = value;
            return callback(null)
        });
    }
}

Charles http packages: