
xdmp.httpPost( uri as String, [options as Object?], [data as Node?] ) as Sequence
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 |
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.
|
http://marklogic.com/xdmp/privileges/xdmp-http-post
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.
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
// 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
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