How to return XML string in http POST

239 views
Skip to first unread message

Santi

unread,
Jul 2, 2015, 3:00:09 AM7/2/15
to cherryp...@googlegroups.com

In POST(self), I read a xml file and modify some of the attributes and do these things:


cherrypy.response.headers['Content-Type'] = 'application/soap+xml;charset=UTF-8'
cherrypy.response.headers['Content-Length'] = len(data)

cherrypy.response.body = data
cherrypy.log("response body is: %s" % cherrypy.response.body)


When the client calls, it won't get the body.


curl and the actual client wait for few seconds and returns this:

curl: (18) transfer closed with 4018 bytes remaining to read


Not sure if I am doing the right thing to send the data back to the client. I took wireshark trace and I am not seeing any data getting sent out from the server.

It seems data is NOT written to the socket.


Can someone please suggest, how to write xml document in POST?



Michiel Overtoom

unread,
Jul 3, 2015, 3:13:25 PM7/3/15
to cherryp...@googlegroups.com

I do it like this:

@expose("somename.xml")
def somename_xml(self):
content = get_some_xml_data()
cherrypy.response.headers["Content-Type"] = "text/xml; charset=utf-8"
return content

CherryPy will determine the Content-Length automatically by itself.

Greetings,


--
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

Reply all
Reply to author
Forward
0 new messages