pythonpost四种方式_Python发送四种格式的post请求的代码样例

x-www-form-urlencoded:

path = "/api/v1/topics/update"

params={'accesstoken':'d38a77f0-6f29-45cd-8d49-f72f15b98fd2','topic_id':'5c89021773798770589936b0','title':'hahaha','tab':'share','content':'hahaha'}

response_text = requests.post(url=self.url+path, data=params).text

# 将响应内容转换成字典格式

response_dict = json.loads(response_text)

# 获取response message字段的值

response_message = response_dict['topic_id']

# 判断message的值

self.assertEqual(response_message, '5c89021773798770589936b0', msg='topic返回值不对')

form-data:

# post request method

response = requests.post(url=url + path, params=params,headers=headers)

# Is the return status code 200?

self.assertEqual(response.status_code, 200, msg="The status code is not 200")

# Is the return message SUCCESS?

response_text = requests.post(url=url + path, params=params,headers=headers).text

# Convert response content into dictionary format.

response_dict = json.loads(response_text)

# Gets the value of the response message.

response_message = response_dict['message']

# Determine the value of message.

self.assertEqual(response_message, 'SUCCESS', msg='The response message is not SUCCESS')

#Print response text.

print(response.text)

标签:Python,text,样例,response,url,params,post,message

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值