Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
8495 มุมมอง

Hello!

How to make Controller with http in response and json in request?


Exists some service with webhooks. Service send json and receive json.

@route type=http rise error on request, becouse income request have json in content-type.

@route type=json make possible do every thing but response. Odoo make jsonrpc response like this:

{"jsonrpc": "2.0", "result": {myjson}}

but for service I need response like this:

{myjson}

I'm try to make decorator @myroute, but find no way to disable error when type=http or change result when type=json


How I can override JsonResponse._json_response() ?

Thank you for any advice!

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Vladislav,

Yes we can send json request from a controller with type=http,

eg:

 import request
 
values = {'id': val_id} 
url = http://demo/url
headers = {'Content-type': 'application/json'}
request = requests.post(url, data=json.dumps(values), headers=headers)
response = request.json()
return response

*response will be in json format

Regards

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ธ.ค. 23
19322
0
พ.ย. 22
2484
2
พ.ค. 24
4984
Controller ignoring args แก้ไขแล้ว
2
ธ.ค. 22
7716
2
พ.ค. 22
4190