通过Python套接字发送GET请求

问题描述 投票:0回答:1

我试图用Python 3.8.2向一个服务器发送一个GET请求。 当我执行命令 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请求有什么问题?

get serversocket python-3.8
1个回答
0
投票

回答我的问题,将这一行替换为 sock.send(b"GET / HTTP/1.1\r\nHost:127.0.0.1\r\n\r\n") 仅凭 sock.send(b"GET") 做到了这一点。

© www.soinside.com 2019 - 2024. All rights reserved.