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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top