Отправить запрос GET через сокет Python - PullRequest
0 голосов
/ 24 апреля 2020

Я пытаюсь отправить запрос GET на сервер с Python 3.8.2. Однако когда я выполняю команду print(sock.recv(1024)), она просто возвращает инструкции, которые были мне даны:

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?

1 Ответ

0 голосов
/ 26 апреля 2020

Отвечая на мой вопрос, замена строки sock.send(b"GET / HTTP/1.1\r\nHost:127.0.0.1\r\n\r\n") на sock.send(b"GET") сделала свое дело.

...