socket访问https

访问https



import socket, ssl

host = 'ip'
port = 443

context = ssl.create_default_context()

conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname="www.baidu.com")

conn.connect(("www.baidu.com", 443))

conn.send(b'GET / HTTP/1.1\r\nHost: www.sina.com.cn\r\nConnection: close\r\n\r\n')

buffer = []

while True:
d = conn.recv(1024)
if not d:
break
buffer.append(d)

data = b''.join(buffer)

conn.close()

print(data)