1. 程式人生 > >Python接口測試-使用requests模塊發送post請求

Python接口測試-使用requests模塊發送post請求

pan files show code post connect ear url sts

本篇主要記錄下使用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請求