вторник, 30 ноября 2010 г.

Как отправить GET-запрос в Python? / How to send GET-request with Python?


#with httplib
import httplib  


def printText(txt):     
  lines = txt.split('\n')     
  for line in lines:         
    print line.strip()  


httpServ = httplib.HTTPConnection("127.0.0.1", 80) 
httpServ.connect()  
httpServ.request('GET', "/test.html")  
response = httpServ.getresponse() 
if response.status == httplib.OK:     
  print "Output from HTML request"     
  printText (response.read())  
  
httpServ.request('GET', '/cgi_form.cgi?name=Brad&quote=Testing.')  
response = httpServ.getresponse() 
if response.status == httplib.OK:     
        print "Output from CGI request"     
        printText (response.read())  
httpServ.close()

Комментариев нет:

Отправить комментарий