kissguan 发表于 2024-9-23 11:32:56

用python写发送post请求

用fiddler抓包的,内容如图,有没有办法通过python发送这段请求,没有cookie和其他内容
GET http://59.207.60.70:9001/elementsCheck/storey/deleteStorey?id=622746 HTTP/1.1Host: 59.207.60.70:9001Connection: keep-aliveAccess-Control-Allow-Origin: *Accept: application/jsonAuthorization: axy1yodu7DkjtACbueZjRzEN3bxBM9O417PU7ncuDeptCode: 143719User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36Content-Type: application/json;charset=utf-8Referer: http://59.207.60.70:9001/micro/gridCms/infoManage/roomArchives/list?current=1&pageSize=10Accept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.9

FishC 发表于 2024-9-23 11:33:09

你好,鱼油!在Python中,你可以使用requests库来发送HTTP请求。下面是一个示例,展示如何构造一个类似你提供的GET请求:

import requests

url = "http://59.207.60.70:9001/elementsCheck/storey/deleteStorey"
params = {
    "id": "622746"
}
headers = {
    "Host": "59.207.60.70:9001",
    "Connection": "keep-alive",
    "Access-Control-Allow-Origin": "*",
    "Accept": "application/json",
    "Authorization": "axy1yodu7DkjtACbueZjRzEN3bxBM9O417PU7ncu",
    "DeptCode": "143719",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36",
    "Content-Type": "application/json;charset=utf-8",
    "Referer": "http://59.207.60.70:9001/micro/gridCms/infoManage/roomArchives/list?current=1&pageSize=10",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9"
}

response = requests.get(url, headers=headers, params=params)

print(response.status_code)
print(response.json())# 如果服务器返回的是JSON数据

确保你已经安装requests库,可以使用以下命令进行安装:
pip install requests

上述代码会发送一个GET请求,并将请求头和参数添加到请求中。你可以根据实际返回的数据格式,修改`response.json()`为`response.text()`来获取非JSON格式的数据。

如果需要发送POST请求,只需将`requests.get`改为`requests.post`即可。希望这个回答能帮到你!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。

kissguan 发表于 2024-9-23 11:34:41

GET http://59.207.60.70:9001/elementsCheck/storey/deleteStorey?id=622746 HTTP/1.1
Host: 59.207.60.70:9001
Connection: keep-alive
Access-Control-Allow-Origin: *
Accept: application/json
Authorization: axy1yodu7DkjtACbueZjRzEN3bxBM9O417PU7ncu
DeptCode: 143719
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
Content-Type: application/json;charset=utf-8Referer: http://59.207.60.70:9001/micro/gridCms/infoManage/roomArchives/list?current=1&pageSize=10
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9

FishC 发表于 2024-9-23 11:34:49

kissguan 发表于 2024-09-23 11:34
GET http://59.207.60.70:9001/elementsCheck/storey/ ...

你好,鱼油!以下是一个用 Python 的 `requests` 库发送你提供的 GET 请求的示例代码:

import requests

url = "http://59.207.60.70:9001/elementsCheck/storey/deleteStorey"
params = {
    "id": "622746"
}
headers = {
    "Host": "59.207.60.70:9001",
    "Connection": "keep-alive",
    "Access-Control-Allow-Origin": "*",
    "Accept": "application/json",
    "Authorization": "axy1yodu7DkjtACbueZjRzEN3bxBM9O417PU7ncu",
    "DeptCode": "143719",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36",
    "Content-Type": "application/json;charset=utf-8",
    "Referer": "http://59.207.60.70:9001/micro/gridCms/infoManage/roomArchives/list?current=1&pageSize=10",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9"
}

response = requests.get(url, headers=headers, params=params)

print(response.status_code)
print(response.text)# 如果返回的数据是JSON格式,可以改用 response.json()

你需要先通过pip安装`requests`库:
pip install requests

这个代码将会发送符合你所提供的GET请求,并包含所有的请求头信息。如果服务器返回的数据是JSON格式,你也可以使用`response.json()`方法来解析返回的内容。

希望这能帮到你!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
页: [1]
查看完整版本: 用python写发送post请求