durusmail: quixote-users: Re: post w/ custom content type for testing
post w/ custom content type for testing
2004-04-23
Re: post w/ custom content type for testing
2004-04-23
Re: post w/ custom content type for testing
Graham Fawcett
2004-04-23
Bud P. Bruegger wrote:
> For testing, I would like to post to my Quixote app with a content type
> of  plain/text.  It seemed that neither urllib nor urllib2 does this.
> Any suggestions on how to wip up a quick test?

urllib2.Request can do it:

     import urllib2

     headers = {'Content-Type':'text/plain'}
     request = urllib2.Request(url, post_data, headers)
     response = urllib2.urlopen(request)

Because there's data, 'POST' is implied, but you have to set the
Content-Type explicitly, or it will assume the content is
application/x-www-form-urlencoded.

-- Graham



reply