通过套接字发送 GET 请求 Python

Send GET request over socket Python

我正在尝试向使用 Python 3.8.2 的服务器发送 GET 请求。但是,当我执行命令 print(sock.recv(1024)) 时,它只是 returns 给我的指令:

b'\n Iniate communication with GET to retrieve the encrypted messages.\n\n Then return the messages decrypted to the server, taking care to ensure each message is split on to a newline\n '

这是我的代码:

#
# Connect over TCP to the following server 'localhost', 10000
# Initiate communication with GET to retrieve the encrypted messages.
# Then return the messages decrypted to the server,
# taking care to ensure each message is split on to a newline
#


import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 10000))
sock.send(b"GET / HTTP/1.1\r\nHost:127.0.0.1\r\n\r\n")
print(sock.recv(1024))

GET请求有问题吗?

回答我的问题,将行 sock.send(b"GET / HTTP/1.1\r\nHost:127.0.0.1\r\n\r\n") 替换为 sock.send(b"GET") 就成功了。