1

I'm using the rest api odoo server to get content data of a model. I tested on Postman, it works well, enter image description here

but when I integrated into the client side (React app), the request returned an error enter image description here

Plz help me solve this problem, maybe the way to add headers at client side is wrong, I handle at front end like this

  setAuthorization(token) {
    this.httpClient.defaults.headers.common["access_token"] = token;
  }
Hoai Truong
  • 512
  • 2
  • 7
  • 17
  • Does this answer your question? [No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API](https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe) – Tân Dec 04 '19 at 04:53
  • No, I wanna mention to 405 error, If I set access_token to headers, I got the 405 error, but If I remove it, 401 returned – Hoai Truong Dec 04 '19 at 05:04
  • `401` status code means the request was not authorized. `405` status code means you cannot use this request type to connect to the server. Something like the method which will caught the request is marked as `text/plain` or `application/xml` or another type... – Tân Dec 04 '19 at 05:13
  • Consider checking content-type in postman and in your frontend. Most probably you have wrong content-type on front – Pavel Shishmarev Dec 07 '19 at 16:19
  • I met this post https://www.odoo.com/es_ES/forum/ayuda-1/question/configure-openerp-server-for-cross-domain-9316. I think the problem does not come from the client side – Hoai Truong Dec 09 '19 at 02:22
  • May I know how did you got accesstoken, ? its official or customized – Tejas Tank Feb 19 '20 at 13:39
  • @Tejas Tank, it's official, just need to request one api to get token from odoo server – Hoai Truong Feb 24 '20 at 11:02
  • @HoaiTruong Please give me steps, I might helps you in detail – Tejas Tank Feb 26 '20 at 11:47

1 Answers1

1

I've fixed it by the way that I allowed method OPTIONS access into the server to check. Go to main.py from restful module to change it

@http.route(_routes, type="http", auth="none", methods=["GET", "OPTIONS"], csrf=False, cors='*')
Hoai Truong
  • 512
  • 2
  • 7
  • 17