当 type="json" 时,Odoo 控制器避免 json-rpc
Odoo controllers avoid json-rpc when type="json"
我有以下路线:
@http.route([
'/whatever/create'
], auth="none", type='json', methods=['POST'], csrf=False)
我正在使用它来发送 post 请求,其正文中包含 json 数据。
有什么方法可以避免在 type="json"
的路由上使用 json-rpc 响应?我只想简单回答 json.
如果不可能,是否有任何方法可以通过使用 `type="http" 来获取 json 放在正文请求中的数据?
@http.route('/whatever/create', auth='public', methods=['POST'], type='http')
def index(self, **kw):
data = request.httprequest.data
return 'success'
以上代码在Odoo中定义
url = "http://localhost:8069/whatever/create"
param = {
"type_operation": "PTI",
"label": "",
}
headers = {'Content-type': 'text/plain'}
r = requests.post(url, data=json.dumps(param), headers=headers)
以上代码是我从 py 文件中请求的
发送请求时您应该更改内容类型
'Content-type': 'application/json' --- > 'Content-type': 'text/plain'
同时返回它时只接受字符串
return {'status': 'success'} ---> return 'success'
我有以下路线:
@http.route([
'/whatever/create'
], auth="none", type='json', methods=['POST'], csrf=False)
我正在使用它来发送 post 请求,其正文中包含 json 数据。
有什么方法可以避免在 type="json"
的路由上使用 json-rpc 响应?我只想简单回答 json.
如果不可能,是否有任何方法可以通过使用 `type="http" 来获取 json 放在正文请求中的数据?
@http.route('/whatever/create', auth='public', methods=['POST'], type='http')
def index(self, **kw):
data = request.httprequest.data
return 'success'
以上代码在Odoo中定义
url = "http://localhost:8069/whatever/create"
param = {
"type_operation": "PTI",
"label": "",
}
headers = {'Content-type': 'text/plain'}
r = requests.post(url, data=json.dumps(param), headers=headers)
以上代码是我从 py 文件中请求的
发送请求时您应该更改内容类型
'Content-type': 'application/json' --- > 'Content-type': 'text/plain'
同时返回它时只接受字符串
return {'status': 'success'} ---> return 'success'