HTTP Post Request

K

kaklis

Hi to all, i want to ask you a question, concerning the best way to do
the following as a POST request:
There is server-servlet that accepts xml commands
It had the following HTTP request headers:

Host: somehost.com
User-Agent: Jakarta Commons-HttpClient
Content-Type: text/xml
Content-Length: 415

and the following request body (reformatted here for clarity):

<?xml version='1.0'?>
<methodCall>
<methodName>search</methodName>
</methodCall>
How can i send the above to the Listener Servlet?
Thanks in advance
 
K

Kushal Kumaran

Hi to all, i want to ask you a question, concerning the best way to do
the following as a POST request:
There is server-servlet that accepts xml commands
It had the following HTTP request headers:

           Host: somehost.com
           User-Agent: Jakarta Commons-HttpClient
           Content-Type: text/xml
           Content-Length: 415

and the following request body (reformatted here for clarity):

           <?xml version='1.0'?>
           <methodCall>
             <methodName>search</methodName>
           </methodCall>
How can i send the above to the Listener Servlet?
Thanks in advance

Use the xmlrpclib module.
 
K

Kushal Kumaran

OK, sending headers with xmlrpclib,
but how do i send the XML message?

Your XML message is an XML RPC message. You will use xmlrpclib like this:

server_proxy = xmlrpclib.ServerProxy(('somehost.com', 80))
result = server_proxy.search()

The call to server_proxy.search will result in an actual XML RPC
message being sent.

Read up on the xmlrpclib documentation here:
http://docs.python.org/library/xmlrpclib.html, and the XMLRPC spec
here: http://www.xmlrpc.com/spec
 
K

kaklis

Ok I got it!
Thank you!!!

A.K

Apparently the server i'm trying to connect accepts only POST
connections. So xmlrpclib is useless.
I think I need the httplib library module.

Any hints?

A.K.
 
K

Kushal Kumaran

Apparently the server i'm trying to connect accepts only POST
connections. So xmlrpclib is useless.
I think I need the httplib library module.

Any hints?

I don't understand. xmlrpclib sends POST requests only. Are you
getting an exception? If so, please post the entire stack trace.

If you want to send the data "by hand", use the httplib module. you
can pass your XML to the HTTPConnection.request method as the "body"
argument.
 
K

kaklis

I don't understand.  xmlrpclib sends POST requests only.  Are you
getting an exception?  If so, please post the entire stack trace.

If you want to send the data "by hand", use the httplib module.  you
can pass your XML to the HTTPConnection.request method as the "body"
argument.

Ok i found it. I sent the xml by hand with httplib module.
i use the last example of http://docs.python.org/library/httplib.html
and it worked.
Thank you very much for your response.

A.K.
 

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,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top