I am trying to connect odoo and ionic 5 using api interface. below is my Odoo controller:
@http.route(’/ionicon/authenpost’,type=“json”,csrf=False,cors="*", auth=“public”,website=False, method=[‘POST’])
def authenPost(self, login,pwd,base_location=None):
env = request.env(context=dict(request.env.context, show_address=False, no_tag_br=True))
db = env.cr.dbname
request.session.authenticate(db,login,pwd)
return request.env['ir.http'].session_info()
deployment is ok and already tested with Postman. the response is ok as well.
but when I tried to call with ionic 5 android app, I got the following error:
`{"status":400,"url":"http://172.20.10.3:8069/ionicon/authenpost","headers":{"date":"Mon, 18 Jan 2021 17:01:05 GMT","content-length":"308","server":"Werkzeug/0.16.1 Python/3.8.2","x-android-selected-protocol":"http/1.0","x-android-response-source":"NETWORK 400","x-android-received-millis":"1610989264019","x-android-sent-millis":"1610989263965","content-type":"text/html"},"error":"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<title>400 Bad Request</title>\n<h1>Bad Request</h1>\n<p><function ionic_conController.authenPost at 0x7fc9687620d0>, /ionicon/authenpost: Function declared as capable of handling request of type 'json' but called with a request of type 'http'</p>\n"}`
actually I already pass ‘application/json’ header. please see the below code:
this.http.sendRequest("http://172.20.10.3:8069/ionicon/authenpost", {
method: 'post',
responseType: 'json',
data:{ 'jsonrpc':'2.0', 'params' : { 'login':'testuser@sample.com', 'pwd':'testabc' }},
headers: {
accept: 'application/json',
'Content-Type': 'application/json'
}}).then(data=>{
console.log(JSON.stringify(data));
}).catch(err =>{
console.log(JSON.stringify(err));
});
I am using
import { HTTP } from '@ionic-native/http/ngx';
Where can i put content-type ?
Best Rgds, jm