python uses request to send post request

Python implements some small tools, which is really convenient

For example, the following post request

import requests

url = "https://zhuweiyou-chatgpt-api.vercel.app/send_message"  # 替换为目标URL
data = {
    "access_token": "11111",
    "prompt": "假设你是一个Python程序员,你需要使用简洁的语言,不能超过50字,请提供一个实用python办公小技巧,并展示代码的执行结果,再使用搞笑易懂的例子进行解答",
}
response = requests.post(url, data=data)
print(response.text)
json_data = response.json()
print(json_data["text"])

The request format is form and the response format is json

The following is the request form json

url = "https://gofly.v1kf.com"  # 替换为目标URL
data = {
    "visitor_id": "1",
    "content": "测试",
    "visitor_name":"python小助手"
}
response = requests.post(url, json=data)
print(response.text)
json_data = response.json()
print(json_data)

It's really very convenient

Guess you like

Origin blog.csdn.net/taoshihan/article/details/133062501