#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2008 Doug Hellmann All rights reserved. # """ """ #end_pymotw_header import urllib import urllib2 query_args = { 'q':'query string', 'foo':'bar' } request = urllib2.Request('http://localhost:8080/') print 'Request method before data:', request.get_method() request.add_data(urllib.urlencode(query_args)) print 'Request method after data :', request.get_method() request.add_header('User-agent', 'PyMOTW (http://www.doughellmann.com/PyMOTW/)') print print 'OUTGOING DATA:' print request.get_data() print print 'SERVER RESPONSE:' print urllib2.urlopen(request).read()