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发送四种格式的post请求的代码样例的更多相关文章

  1. 关于计算机学习的书(doc,mobi,epub,pdf四种格式)

    关于计算机学习的书(doc,mobi,epub,pdf四种格式) <html> <body> <div> 21天学通C+ +2016/6/22 18:47文條 30 ...

  2. php curl模拟post请求提交数据样例总结

    在php中要模拟post请求数据提交我们会使用到curl函数,以下我来给大家举几个curl模拟post请求提交数据样例有须要的朋友可參考參考.注意:curl函数在php中默认是不被支持的,假设须要使用 ...

  3. (七)四种常见的post请求中的参数形式

    原文链接:https://blog.csdn.net/jiadajing267/article/details/87883725 1).HTTP 协议是以 ASCII 码 传输,建立在 TCP/IP ...

  4. requests(一): 发送一个json格式的post请求

    今天给一位同学解决post发送数据格式为json格式的请求,顺便确认一下问题归属. 背景: 用postman工具发送一个数据格式为json的请求,得到了服务器的响应. 用python的requests ...

  5. java发送application/json格式的post请求,需要登陆

    package util; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWri ...

  6. PyCharm 中文教程 01:运行 Python 的四种方式

    <PyCharm 中文指南>在线阅读: http://pycharm.iswbm.com/ Github 项目主页: https://github.com/iswbm/pych... 1. ...

  7. 方法重载、方法重写、四种权限修饰、JavaBean、代码块

    方法重载(overload) 一个类中可以含有多个重名的方法. 两同一不同 ①同一个类 ②同一个方法名 ③不同参数列表:参数个数不同,参数类型不同 方法重写(override) ①子类重写的方法的修饰 ...

  8. Python代码样例列表

    扫描左上角二维码,关注公众账号 数字货币量化投资,回复“1279”,获取以下600个Python经典例子源码 ├─algorithm│       Python用户推荐系统曼哈顿算法实现.py│    ...

  9. python3编写发送四种http请求的脚本

    python3编写发送http请求的脚本 使用requests包: http://docs.python-requests.org/zh_CN/latest/user/quickstart.html ...

随机推荐

  1. 二、idea + git

    1.配置git file->setting->git Test 2.配置gitHub 2.1 生成gitHub  settings->Developer settings->P ...

  2. Lab 1-1

    LABS The purpose of the labs is to give you an opportunity to practice the skills taught in the chap ...

  3. Configuring Groovy SDK within IntelliJ IDEA

    一.原因 IntelliJ IDEA期待一个the standard Groovy SDK    二.解决方案: 下载安装Groovy就可以了   官网下载地址: http://groovy-lang ...

  4. LeetCode--455--分发饼干

    问题描述: 假设你是一位很棒的家长,想要给你的孩子们一些小饼干.但是,每个孩子最多只能给一块饼干.对每个孩子 i ,都有一个胃口值 gi ,这是能让孩子们满足胃口的饼干的最小尺寸:并且每块饼干 j , ...

  5. linux基础3

    vim编辑器 vim 操作命令 在命令模式下操作 pageup 往上翻页(重要指数****) pagedown 往下翻页(重要指数****) H 移动到屏幕首行 gg 移动光标到文档的首行(重要指数* ...

  6. vux, vue上拉加载更多

    <template> <" :bottom-method="loadBottom" :bottom-all-loaded="bottomAll ...

  7. 小程序点击跳转外部链接 微信小程序提示:不支持打开非业务域名怎么办 使用web-view 配置业务域名

    小程序点击跳转外部页面 1.index.wxml  添加点击事件   标签可以是小程序支持的 <!-- 邀请好友 --> <cover-image src='/img/invitat ...

  8. yii框架中获取添加数据后的id值

    Yii::$app->db->createCommand()->insert('month4_user',['openid'=>$openid,'integ'=>0])- ...

  9. 封装jsonp

    1.写一个类封装jsonp: jsonp(url, params, success, funName)     参数url:请求地址     参数params:请求数据,可以是json对象,或形如&q ...

  10. JS代码判断IE6,IE7,IE8,IE9

    做网页有时候会用到JS检测IE的版本,下面是检测Microsoft Internet Explorer版本的三种代码! 有一种代码: <script type="text/javasc ...