python requests 发起http POST 请求,带参数,带请求头:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import requests
import json

url = 'http://official-account/app/messages/group'
body = {"type": "text", "content": "测试文本", "tag_id": "20717"}
headers = {'content-type': "application/json", 'Authorization': 'APP appid = 4abf1a,token = 9480295ab2e2eddb8'}

#print type(body) #print type(json.dumps(body))

# 这里有个细节,如果body需要json形式的话,需要做处理 # 可以是data = json.dumps(body) response = requests.post(url, data = json.dumps(body), headers = headers)

# 也可以直接将data字段换成json字段,2.4.3版本之后支持 # response = requests.post(url, json = body, headers = headers)
# 返回信息 print response.text

# 返回响应头 print response.status_code

  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2021-10-02
  • 2021-09-27
猜你喜欢
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-03
  • 2022-01-19
  • 2021-08-11
相关资源
相似解决方案