requests包是python语言里的一个发送请求的很好用的包,它集成了很多http请求方式,本文重点介绍一下post的提交形式。
服务端的API有的接受form表单提交,有的接受json数据提交,他们的python编写区别如下:
form:
header = {
"Content-Type": "application/x-www-form-urlencoded"
}
requests.post(url , data={"appname": '111'}, headers=header)
json:
header = {
"Content-Type": "application/json"
}
requests.post(url , data={"appname": '111'}, headers=header)
两者的主要区别在于headers里。

requests包在Python中用于发送HTTP请求,POST方法支持form表单和JSON数据提交。区别在于Content-Type头,form使用application/x-www-form-urlencoded,而JSON则需设置为application/json。
3万+

被折叠的 条评论
为什么被折叠?



