passing data to a liburl2 opener object

S

scriptlearner

I have prepared my headers and data for a HTTP POST message; however,
I am not sure how to pass the data to the opener. Can you guys
provide some suggestions? Thanks.


proxy_handler = urllib2.ProxyHandler({'http': 'http://my.proxy.com:
3128/'})
opener = urllib2.build_opener(proxy_handler)

url = "http://sample.company.com:9999/service?"

headers['Content-Type'] = 'multipart/form-data; boundary=%s' %
myBoundar
headers['Cookie'] = 'somevalidcookiecontents'
#there is an opener.addheaders method for adding headers
data = multipart_encode(myDict)
#how to pass data to the opener???


With the codes above, I need to send out a HTTP POST like the
following one:

POST http://sample.company.com:9999/service?
Content-Type: multipart/form-data;
boundary=---------------------------1234

---------------------------1234
Content-Disposition: form-data; name="picture"

PICTURE contents here
---------------------------1234
Content-Disposition: form-data; name="id"

whateverid
---------------------------1234--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top