python使用request发送post请求

python实现一些小工具,真的非常方便

比如下面的post请求

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"])

请求形式为form,响应形式为json

下面的是请求形式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)

真的是非常方便

猜你喜欢

转载自blog.csdn.net/taoshihan/article/details/133062501