Untitled
unknown
plain_text
a year ago
831 B
7
Indexable
import http.client
import time
def send_get_request(conn, path):
conn.request("GET", path)
response = conn.getresponse()
print(f"Status: {response.status}, Reason: {response.reason}")
response.read() # 读取响应体以完成请求
def main():
host = "localhost:8080" # 替换为目标服务器的主机名或IP地址
path = "/api/hello" # 替换为你要请求的路径
# 创建一个 HTTP 连接
conn = http.client.HTTPConnection(host)
try:
# 发送初始请求
send_get_request(conn, path)
# 定义时间间隔(秒)
intervals = [10, 50]
for interval in intervals:
time.sleep(interval)
send_get_request(conn, path)
finally:
conn.close() # 关闭连接
if __name__ == "__main__":
main()
Editor is loading...
Leave a Comment