I am encountering a CORS (Cross-Origin Resource Sharing) error when making a POST request to an API endpoint in Odoo from a web page. The error occurs when the browser attempts to send data to the endpoint, while the request works fine using tools like Postman. The browser’s console shows a CORS error indicating that the request is blocked due to missing or incorrect CORS headers. Despite including headers like Content-Type: application/json the issue persists. The Odoo server logs indicate that an OPTIONS request is sent before the POST request, which is typical for preflight requests to check CORS permissions. However, the server-side configuration may not be set up to handle these OPTIONS requests correctly.
This is my route
@http.route('/api/create_employee', type='json', auth='none', methods=['POST'], csrf=False, cors='*')
headers={
'Access-Control-Allow-Origin': '*',}type here
Thank you in advance for your help!
How to solve this issue
Rajesh Dattathri Bobade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.