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

Posted 碎片拾零

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python接口测试-使用requests模块发送post请求相关的知识,希望对你有一定的参考价值。

本篇主要记录下使用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请求的主要内容,如果未能解决你的问题,请参考以下文章