程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How to do interface test for Python request

編輯:Python

During the test , A large amount of test data may be required , have access to Python Programming languages do a lot of interface requests for us

1, With post The way to request

import request # Leading package
re = requests.post(url="https://www.csdn.net",data={"a":1},headers={"token":"q1231"}) # add to url, Add request body, Add request headers
print(re.json()) # Return content json Format
print(re.text) # Return content text format 

2, With get Method request for

import requests # Leading package
re = requests.get(url="https://www.csdn.net?a=1",headers={"a":1}) # add to url, Add request headers, the reason being that get request , So there is no need to add a request body, Requested parameter join url Just inside
print(re.json()) # Response content format 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved