37,721
社区成员
发帖
与我相关
我的任务
分享
import socket
target_host = 'www.baidu.com'
target_port = 80
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((target_host, target_port))
msg = 'get / http/1.1\r\nHost:baidu.com\r\n\r\n'
client.send(msg.encode('utf-8'))
response = client.recv(4096)
print(response)
client.close
>>> s = b'hello, world'
>>> s
b'hello, world'
>>> str(s)
"b'hello, world'"
>>> s.decode('ascii')
'hello, world'