xdmp:http-post( $uri as xs:string, [$options as (element()|map:map)?], [$data as node()?] ) as item()+
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.
You can specify options as either an XML element
in the "xdmp:http" namespace, or as a map:map . The
options names below are XML element localnames. When using a map,
replace the hyphens with camel casing. For example, "an-option"
becomes "anOption" when used as a map:map key.
This function supports the following options, plus the options from the
xdmp:http-get
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:http-post("http://www.my.com/document.xhtml", <options xmlns="xdmp:http"> <authentication method="basic"> <username>myname</username> <password>mypassword</password> </authentication> </options>) => the response from the server as well as the specified document
(: Use xdmp:quote to encode the XML as a string because the <data> options element is a string :) let $payload := xdmp:quote( <SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:my='urn:MyConnection'> <SOAP-ENV:Body> <my:LogOn> <my:User>user</my:User> <my:Password>pass</my:Password> <my:Ticket>abc123</my:Ticket> <my:newData>1234</my:newData> </my:LogOn> </SOAP-ENV:Body> </SOAP-ENV:Envelope> ) return xdmp:http-post("http://www.my.com/document.xhtml", <options xmlns="xdmp:http"> <authentication method="basic"> <username>myname</username> <password>mypassword</password> </authentication> <data>{$payload}</data> <headers> <content-type>application/xml</content-type> </headers> </options>) => the response from the server as well as the specified document
xquery version "1.0-ml"; let $payload := '{ "user-name": "joe", "password": "cool" ,"role": [ "rest-reader" , "rest-writer" ] }' return xdmp:http-post("http://localhost:8002/manage/v2/users?format=json", <options xmlns="xdmp:http"> <authentication method="digest"> <username>myname</username> <password>mypassword</password> </authentication> <headers> <content-type>application/json</content-type> </headers> <data>{$payload}</data> </options>) => the response from the server, and in this example, the new user (joe) is created