Форум сайта python.su
Всем добрый день!
Стоит задача написать самый простой SSL-клиент с использованием socket
import socket, ssl ''' write a SSL client using a socket ''' host = "www.verisign.com" port = 443 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) wrapped_socket = ssl.wrap_socket(s) wrapped_socket.connect((host, port)) print(repr(wrapped_socket.getpeername())) wrappedSocket.send(b"HEAD / HTTP/1.0\r Host: www.verisign.com\r\nUser-agent: Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405\r\n\r\n") string = wrapped_socket.recv(1024) #data = wrapped_socket.read() #print(data) print(string) wrapped_socket.close()
('72.13.63.55', 443)
b'HTTP/1.1 200 OK\r\nDate: Tue, 22 Dec 2015 09:21:15 GMT\r\nServer: Apache\r\nSet-Cookie: JSESSIONID=C2FC6726DEAD0B6270F8E444E5B15C63.brn1lxwwwapp03; Path=/; Secure; HttpOnly\r\nSet-Cookie: locale-name=en_US; Version=1; Comment=“User\'s choice to override their browser\'s default locales.”; Max-Age=999999999; Expires=Fri, 30-Aug-2047 11:07:54 GMT; Path=/\r\nContent-Language: en-US\r\nVary: Accept-Encoding\r\nConnection: close\r\nContent-Type: text/html;charset=UTF-8\r\n\r\n
Отредактировано Moi5es (Дек. 22, 2015 11:26:14)
Офлайн