post xml payload with urllib

B

brad

Has anyone sent an xml payload via post using urllib? I'd like to do
something like this:

logon_request = """<LoginRequest>
<password>"the_password"</password>
<user>"the_user"</user>
</LoginRequest>"""

logon = urllib.urlopen("https://127.0.0.1/api/version/xml", logon_request)
print logon.read()
logon.close()

127.0.0.1 expects xml via a https connection post.
 
M

mirandacascade

Has anyone sent an xml payload via post using urllib?

Haven't used urllib, but have used urllib2 to do a POST.

Might something like this work...

import urllib2

logon_request = """<LoginRequest>
<password>"the_password"</password>
<user>"the_user"</user>
</LoginRequest>"""

req = urllib2.Request("https://127.0.0.1/api/version/xml",
data=logon_request)
openObj = urllib2.urlopen(req)
response = openObj.read()
 

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

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top