Error on Passing postdata on Ionic 5 to odoo

Hi there,

I am passing postdata to odoo api. When i tried with postman, it is ok and response is what i expected. but I tried to access via IONIC, always failed. the here is the response:

{“headers”:{“normalizedNames”:{},“lazyUpdate”:null,“headers”:{}},“status”:0,“statusText”:“Unknown Error”,“url”:“http://127.0.0.1:8069/supercon/authenpost",“ok”:false,“name”:“HttpErrorResponse”,“message”:"Http failure response for http://127.0.0.1:8069/supercon/authenpost: 0 Unknown Error”,“error”:{“isTrusted”:true}}"

below is the code i tried.

var headers = new HttpHeaders({

  'Content-Type':'application/json',

  'Accept' : 'application/json'

});



let options = {

  headers: headers

}

let postData = {

        "jsonrpc": "2.0",

        "params": "{\"login\":\"tesuser@test.com\", \"pwd\":\"samplepwd\"}"

}

this.httpClient.post("http://127.0.0.1:8069/supercon/authenpost", postData, options)

  .subscribe(data => {

    console.log('NO ERROR' + JSON.stringify(data));

   }, error => {

    console.log('ERROR' + JSON.stringify(error));

  });

when i tried with Nodejs , it is working too.below is the nodejs code.

var http = require('follow-redirects').http;
var fs = require('fs');

var options = {
  'method': 'POST',
  'hostname': 'localhost',
  'port': 8069,
  'path': '/supercon/authenpost',
  'headers': {
    'Content-Type': 'application/json'
  },
  'maxRedirects': 20
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function (chunk) {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });

  res.on("error", function (error) {
    console.error(error);
  });
});

var postData = JSON.stringify({"jsonrpc":"2.0","params":{"login":"testuser@test.com","pwd":"samplepwd"}});

req.write(postData);

req.end();

below is another javascript that i tried, it is working too.

var data = JSON.stringify({"jsonrpc":"2.0","params":{"login":"testuser@test.com","pwd":"samplepwd"}});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "http://localhost:8069/supercon/authenpost");
xhr.setRequestHeader("Content-Type", "application/json");


xhr.send(data);

How can i use to connect using typescript on ionic 5?

Best Rgds,
frog

I can be wrong but you don’t need extra quotes and escaping:

let postData = {
    jsonrpc: "2.0",
    params: {
         login:"tesuser@test.com",
         pwd:"samplepwd"
    }
}

Nor do you need manual JSON marshalling and unmarshalling or micromanaging headers to set Content-Type.

for odoo i use jsonrpc 2.0, the rest is normal.

take a screenshot of app request data in chrome devtool

i am using android emulator.

you can use chrome://inspect

hi ghostriderus,

I got the following two error:

the first one:

Failed to load resource: net::ERR_CONNECTION_REFUSED

second one:

{“headers”:{“normalizedNames”:{},“lazyUpdate”:null,“headers”:{}},“status”:0,“statusText”:“Unknown Error”,“url”:“http://127.0.0.1:8069/supercon/authenpost",“ok”:false,“name”:“HttpErrorResponse”,“message”:"Http failure response for http://127.0.0.1:8069/supercon/authenpost: 0 Unknown Error”,“error”:{“isTrusted”:true}}"

try to replace 127.0.0.1 to 10.0.2.2

10.0.2.2 I have to replace with my computer ip. isn’t it?

Android emulator connect to localhost of host system by 10.0.2.2 address

This is my git repo, I modified the angular7 odoo-jsonrpc module and using it.It requires native HTTP for perfect operation…
Download the source and place the folder starting with ‘manikandan’ and follow the instructions provided in readme.md…