[XQZone General] interfacing servlet from xqy file

Ron Hitchens ron.hitchens at marklogic.com
Tue Aug 9 12:39:47 PDT 2005

On Aug 9, 2005, at 10:41 AM, Ciano.William wrote:

> How can I send a parameter (say, name="Bob") to a servlet from  
> a .xqy file using the xdmp:http-post() method ?  Does someone have  
> a code example ?

    For an HTTP POST, the parameters are sent in the body
rather than using the query string ("?") in the URL.  Some
servlet containers may accept query string parameters on
POST requests, but you can't rely on that.

    The way parameters are encoded in a POST body varies,
depending on the type of the parameters.  For simple
name/value pairs, a POST request looks like this:

Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us)  
AppleWebKit/412.6 (KHTML, like Gecko) Safari/412.2
Content-Type: application/x-www-form-urlencoded
Content-Length: 18
Connection: keep-alive
Host: localhost:8088


    If you're doing something more complicated, such as
posting files, there's a more complex multi-part encoding
that I'm too lazy to lookup right now.

    The important thing is to include the header:

      Content-Type: application/x-www-form-urlencoded

    And to properly URL-encode the parameter values
(xdmp:url-encode).  Also set the Content-Length if
you can calculate it.

    Header values for the POST and the data for the
body are set via the $options parameter to xdmp:http-post.

Ron Hitchens {ron.hitchens at marklogic.com}  650-655-2351

More information about the General mailing list