Hi all:

I'm trying expose a function for REST, more specifically to accept HTTP 
POST request with XML message in the body. Following this article 
http://www.web2py.com/AlterEgo/default/show/197, I use *request.body.read()*to 
get the xml message. The code is:

def api():
   *xml = request.body.read()  # retrieve the raw POST data*

    logger.debug("Message XML Content:  %s" % xml )

    if len(xml) == 0:
        xml = '<?xml version="1.0" encoding="utf-8" ?><root>no post 
data</root>'
        raise HTTP(400) #malformed
    else:
        now = datetime.datetime.now()
        date_time = now.strftime("%Y-%m-%d %H:%M:%S")
        
db.messages.validate_and_insert(date_time=date_time,xmlcontent=XML(xml))

    raise HTTP(200) #OK


When I test the code with curl and a XML message in a file everything 
works, web2py extract the xml message and raise HTTP(200).  But when on a 
production environment (other server sending HTTP Post requests) 
*request.body.read() 
*can't read the body. In fact there's no error, simply the xml variable is 
empty. 

I've capture a trace with wireshark and the production server is really 
sending HTTP Post requests with XML. It appears as:

POST /cosa/default/api HTTP/1.1 
Transfer-Encoding: chunked 
Content-Type: application/xml 
Host: 83.165.4.139:8000 
Connection: Keep-Alive 
User-Agent: Apache-HttpClient/4.2.2 (java 1.5) 
 
330 
<choMessage>
  <choData>
    <choID>71</choID>
    <data>
. . . . . . .
    </data>
    <data>
. . . . . . . 
    </data>
  </choData>
</choMessage> 
0 
 
HTTP/1.1 400 BAD REQUEST 
Set-Cookie:  
session_id_cosa=217.130.7.151-fecabd8f-2b3e-4f7b-9029-5777d25c8e7e; Path=/ 
Content-Length: 15 
Content-Type: text/html; charset=UTF-8 
Date: Sat, 06 Apr 2013 07:40:36 GMT 
Server: Rocket 1.2.6 Python/2.7.3 
Connection: keep-alive 
 
400 BAD REQUESTHTTP/1.1 400 Bad Request
Content-Length: 11
Content-Type: text/plain

Bad Request


Any idea what is happenning? Why web2py is not able to read the body? What 
am I doing wrong?

Thanks in advance

Jes



-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to