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
2 posts - 2 participants