如何通过Python中的POST请求发送ASCII编码文本?我通过POST收到的true_input
的长度总是与我发送的长度不同。如何在Python中使用POST请求保留Ascii编码类型?
def insert_true_input(level, iteration, true_input):
url = master_url + "/insert_true_input?"
data = {'level': level, 'iteration': iteration, 'true_input': true_input}
headers = {'Content-Type': 'text/plain'}
res = requests.post(url, params=data, headers=headers).text
return res
,我想送的小样true_input是直接从numpy.ndarray.tostring()
貌似
'\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\[email protected]\x00\x00\x00\x00\x00\x00\[email protected]\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\[email protected]\x00\x00\x00\x00\x00\xc0^@\x00\x00\x00\x00\x00\xc0^@\x00\x00\x00\x00\x00\xc0^@\x00\x00\x00\x00\x00\x00(@\x00\x00\x00\x00\x00\[email protected]'
你想什么做做到了吗?你想要在请求正文中发布数据,还是将它传递给查询字符串?通过对'requests.post()'使用'params'参数,你实际上使用了一个查询字符串来发布数据,而不是请求主体。如果你想将它作为主体传递,请使用'data'参数,并移除你自定义的Content-Type头(请求将自动使用Content-Type'application/x-www-form-urlencoded')。 – Guillaume
请为“true_input”和样本输出(完整的HTTP请求标头和正文)提供一个示例输入,它会让您更容易理解您想要的内容。 – Guillaume
@Guillaume谢谢你的回答!请看我更新的问题。 – xxx222