Loading TOC...

xdmp.httpPost

xdmp.httpPost(
   $uri as String,
   [$options as Object?],
   [$data as Node?]
) as Sequence

Summary

Sends an http POST request to the server.

Parameters
$uri The URI to which the data is to be posted.
$options Options with which to customize this operation. This function supports the following options, plus the options from the xdmp.httpGet function.

data

This option can contain any string. Anything in the data option is sent as a string in the PUT or POST body. When POSTing to a web service, the data may need to be a SOAP XML structure, a JSON structure, or binary content. The optional third argument can be used to specify the body instead.

The other options are the same as the other xdmp.http* functions, and the options are documented with the xdmp.httpGet $options parameter.

$data The data for this request. This is an alternative to the data option for the second parameter that allows binary content to be specified for the body of the POST.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-http-post

Usage Notes

The http functions only operate on URIs that use the http or https schemes; specifying a URI that does not begin with http:// or https:// throws an exception.

If an http function times out, it throws a socket received exception (SVC-SOCRECV).

The function returns a sequence containing the request response. If the reponse is multi-part, then the sequence contains multiple items.

If you expect the request body from this http function to be processed by another application (via a web service, for example), you should specify a content-type header. If no content-type header is specified, the content type defaults to text/plain.

Example

xdmp.httpPost("http://www.my.com/document.xhtml",
     {
       "authentication" : {
         "method" : "basic",
         "username" : "myname",
         "password" : "mypassword"
       }
     });
=> the response from the server as well as the specified document

Example

//  Use xdmp.quote to encode the JSON as a string
//  because the "data" option is a string 

var payload = xdmp.quote({"foo":"bar"})
xdmp.httpPost("http://www.my.com/document.xhtml",
     {
       "authentication" : {
          "method" : "basic",
          "username" : "myname",
          "password" : "mypassword"
       },
       "data" : payload,
       "headers" : {
         "content-type" : "application/xml"
       }
     });
=> the response from the server as well as the specified document

Example

var payload = xdmp.quote({"userName": "joe", "password": "cool" , 
	"role": [ "rest-reader" , "rest-writer" ] }); 
xdmp.httpPost("http://localhost:8002/manage/v2/users?format=json",
     {
       "authentication" : {
          "method" : "digest",
          "username" : "myname",
          "password" : "mypassword"
       },
       "data" : payload,
       "headers" : {
         "content-type" : "application/json"
       }
     })
=> the response from the server, and in this example, the new user (joe) is 
   created

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy