【发布时间】:2020-11-10 11:19:42
【问题描述】:
我有一个实现如下:
-
有一个付款表格,用户填写所有详细信息。(API1),这里我收到错误 302:
-
在提交该表单时,我认为调用了其中一个函数。
-
在后端实现中,即。在
views.py中,我想向我已集成的网关之一发送 POST 请求。(API2)
但是问题来了,因为请求是以 GET 方式进行的,因此它会丢弃我与请求一起发送的所有表单数据。
以下是代码。
views.py -->
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
payload = {
'CustomerID': 'abc',
'TxnAmount': '1.00',
'BankID': '1',
'AdditionalInfo1': '999999999',
'AdditionalInfo2': 'test@test.test',
}
payload_encoded = urlencode(payload, quote_via=quote_plus)
response = requests.post('https://www.billdesk.com/pgidsk/PGIMerchantRequestHandler?hidRequestId=****&hidOperation=****', data=payload_encoded, headers=headers)
content = response.url
return_config = {
"type": "content",
"content": redirect(content)
}
return return_config
如何将第二个请求 (API2) 作为 POST 请求连同所有参数一起发送?我在这里做错了什么?
感谢您的建议。
【问题讨论】:
-
为什么不能在 POST 方法中执行,而不是在视图的重定向 GET 方法中执行。
-
你为什么要返回一个重定向?您在请求后从该外部服务获得结果,您可以使用该结果生成响应。你需要看看为什么你会得到 302 状态。
-
抱歉不清楚你想达到什么目的
标签: python-3.x django django-request