Code: Alles auswählen
import socket
#~ host = "www.google.de"
#~ host = "www.heise.de"
host = "www.microsoft.com"
port = 80
#~ url = "/gibt_es_nicht_test"
url = "/"
print "Connecte zu %s:%s..." % (host, port),
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
print "OK"
request = [
"GET %s HTTP/1.1" % url,
"Host: %s:%s" % (host, port),
"User-Agent: Python",
"Accept: text/*",
"Accept-Charset: ISO-8859-1,utf-8",
"Connection: close",
]
request = "\r\n".join(request)
request += "\r\n\r\n"
print "Send Request '%s'..." % request.encode("String_Escape"),
s.send( request )
print "OK"
print "Read data...",
data = ""
while 1:
block = s.recv(1024)
if not block:
break
data += block
print "OK"
print "_"*80
print data.encode("String_Escape")
print "_"*80
print data
s.close()
Connecte zu www.google.de:80... OK
Send Request 'GET /gibt_es_nicht_test HTTP/1.1\r\n\r\n'... OK
Read data... OK
________________________________________________________________________________
HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\nServer: GWS/2.1\r\nContent-Length: 1259\r\nDate: Wed, 20 Jul 2005 19:12:07 GMT\r\n\r\n\n\n<html><head>
________________________________________________________________________________
HTTP/1.1 404 Not Found
Content-Type: text/html
Server: GWS/2.1
Content-Length: 1259
Date: Wed, 20 Jul 2005 19:12:07 GMT
<html><head>