Python 使用requests模块发送GET和POST请求的实现代码

时间:2022-01-19 15:53:27

GET

?
1
2
3
4
5
6
7
8
# -*- coding:utf-8 -*-
 
import requests
 
def get(url, datas=None):
  response = requests.get(url, params=datas)
  json = response.json()
  return json

注:参数datas为json格式

POST

?
1
2
3
4
5
6
7
8
# -*- coding:utf-8 -*-
 
import requests
 
def post(url, datas=None):
  response = requests.post(url, data=datas)
  json = response.json()
  return json

注:参数datas为json格式

原文链接:http://blog.csdn.net/wudj810818/article/details/50250511