首页 > 其他 > 详细

odoo 接口跨域请求报错

时间:2021-08-19 14:36:40      阅读:9      评论:0      收藏:0      [点我收藏+]

浏览器显示的信息如下:
from origin ‘http://www.docway.net‘ has been blocked by CORS policy: The value of the ‘Access-Control-Allow-Credentials‘ header in the response is ‘‘ which must be ‘true‘ when the request‘s credentials mode is ‘include‘. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
参考了该博主的文章:https://www.jinxiaoliang.cn/V/213.html
对odoo 的代码修改如下:

# 第一处
    @http.route(
        "/api/auth/token", methods=["GET","OPTIONS"], type="http", auth="none", csrf=False,cors=‘http://www.docway.net‘,
        save_session=False
    )
	
	#第二处:
	        if request.endpoint and ‘cors‘ in request.endpoint.routing:
            self.headers.set(‘Access-Control-Allow-Origin‘, request.endpoint.routing[‘cors‘])
            self.headers.set(‘Access-Control-Allow-Credentials‘, ‘true‘) # 改
            methods = ‘GET, POST‘
            if request.endpoint.routing[‘type‘] == ‘json‘:
                methods = ‘POST‘
            elif request.endpoint.routing.get(‘methods‘):
                methods = ‘, ‘.join(request.endpoint.routing[‘methods‘])
            self.headers.set(‘Access-Control-Allow-Methods‘, methods)
			
	# 第三处:
	        if request.httprequest.method == ‘OPTIONS‘ and request.endpoint and request.endpoint.routing.get(‘cors‘):
            headers = {
                ‘Access-Control-Max-Age‘: 60 * 60 * 24,
                ‘Access-Control-Allow-Headers‘: ‘Origin, X-Requested-With, Content-Type, Accept, X-Debug-Mode‘
                ,‘Access-Control-Allow-Credentials‘:‘true‘ # 改
            }
            return Response(status=200, headers=headers)

odoo 接口跨域请求报错

原文:https://www.cnblogs.com/qianxunman/p/15161092.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!