首页 > 编程语言 > 详细

Python接口测试-使用requests模块发送post请求

时间:2017-11-18 22:51:19      阅读:831      评论:0      收藏:0      [点我收藏+]

本篇主要记录下使用python的requests模块发送post请求的实现代码.

 

#coding=utf-8
import unittest
import requests

class PostTest(unittest.TestCase):

    def setUp(self):
        host = https://httpbin.org/
        endpoint = post
        self.url = ‘‘.join([host, endpoint])

    def testPost(self):
        params = {show_env:1}
        json = {
            info: {show_env: 2, sex: nv},
            code: 200,
            a: hello, b: nihao,
            files : {file: (test.txt, hello)},
            data: [{name: zhangsan, id: 123}, {name: lisi, id: 125}],
            id: 1900
        }

        r1 = requests.post(self.url,params=params,json=json)
        resp1 = r1.json()
        print(resp1)
        connect = resp1[headers][Connection]
        self.assertEqual(connect, close)

    def tearDown(self):
        pass

if __name__==__main__:
    unittest.main()

 

Python接口测试-使用requests模块发送post请求

原文:http://www.cnblogs.com/feiyueNotes/p/7857977.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!