Python 简单的带参数Post请求

Post请求

import json
import requests


host = "192.168.1.111"
port = "9999"

def get_data():
    req_url = f"http://{host}:{port}/professional/python/getTaskGivePython"
    pre_data = {"key": "value"}
    headers = {"content-type": "application/json"}
    param = json.dumps(pre_data)
    try:
        resp = requests.post(req_url, data=param, headers=headers)
        resp.raise_for_status()
        print(resp.status_code)
        return resp.json()
    except Exception as Error:
        print(Error)


data = get_data()
print(type(data))
posted @ 2020-11-17 16:04  道友请留步W  阅读(1182)  评论(0)    收藏  举报