Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
3397 Näkymät

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='*')

This is my header 

response = request.make_response(
json.dumps({'message': 'Employee created successfully'}),
headers={
'Access-Control-Allow-Origin': '*', # Adjust to restrict access as needed
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization, talview-odoo-api',
'Access-Control-Allow-Credentials': 'true',
"Content-Type": "application/json"
}
)
return response


Thank you in advance for your help!


Avatar
Hylkää
Paras vastaus

Hi, did you find a solution?

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
toukok. 25
1118
1
maalisk. 24
1133
0
syysk. 23
8023
1
kesäk. 25
1636
1
kesäk. 25
603