请注意,我使用的是Python语言进行编写:
import socket
def send_request(host, port, path):
"""
Send a GET request to a server with the specified host, port, and path.
Returns the response from the server.
"""
# Create a socket and connect to the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
# Send the GET request to the server
request = "GET {} HTTP/1.1rnHost: {}rnrn".format(path, host)
s.send(request.encode())
# Receive the response from the server
response = ""
while True:
data = s.recv(1024)
if not data:
break
response += data.decode()
# Close the connection to the server
s.close()
return response
# Send a request to Server 1
response1 = send_request("server1.com", 80, "/path/to/resource")
# Send a request to Server 2
response2 = send_request("server2.com", 80, "/path/to/other/resource")