get请求

import requests

base_url = 'http://httpbin.org'

# 定义请求所需的参数,参数之间以英文逗号隔开
param_data = {'uname':'Test00001','pwd':'123456'}
# 发送GET请求,格式如:requests.get(url,params)
r = requests.get(base_url+'/get',params=param_data)
print(r.url)    # 输出请求的url
print(r.status_code)    #输出响应的状态码

post请求 写法一:

import requests
payload = dict(key1='value1', key2='value2')
r = requests.post('http://httpbin.org/post', data=payload)
print(r.text)

post 请求写法二:

import requests
import json
payload = {"key1":'value1',"key2" :'value2'} #字典
json_payload = json.dumps(payload) #字典变成json
r = requests.post('http://httpbin.org/post', json=json_payload)
print(r.text)