xdmp.httpGet( uri as String, [options as Object?] ) as Sequence
Sends the http GET method to the specified URI. Returns the http response as well as whatever information is identified by the specified URI (for example, an html document).
Parameters | |
---|---|
uri | The URI of the requested document. |
options |
Options with which to customize this operation.
This function supports the following options, plus certain options from the
xdmp.documentLoad
and
xdmp.documentGet
functions. For example, you can use the repair and
encoding options from these functions.
|
http://marklogic.com/xdmp/privileges/xdmp-http-get
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).
An automatic encoding detector will be used if the value auto
is specified for the encoding
option
. If no option is specified, the encoding defaults to
the encoding specified
in the http header. If there is no encoding in the http header, the encoding
defaults to UTF-8.
The first node in the output of this function is the response header from the http server.
The second node in the output of this function is the
response from the http server. The response is treated as
text, XML, JSON or binary, depending on the content-type header sent from
the http server. If the node is html, the header should indicate
text/html
, which is returned as a text document by default.
The type of document is determined by the mimetypes mappings, and
you can change the mappings in the Admin Interface as needed.
To use this function with a proxy, you need to translate the URI to the proxy uri. For example:
function httpGetProxy(proxy, uri) { var host = fn.subsequence(fn.tokenize(uri,'/'), 3, 3); // you might need to modify the next line based on your proxy server config var proxyuri = fn.concat(proxy, uri); return xdmp.httpGet(proxyuri, {headers:{host: host}}); }; httpGetProxy('http://some.proxy.com:8080','http://www.google.com');
If you use the credentialId
option,
you can use xdmp.credentialId
to obtain the id of a previously stored credential. For example:
xdmp.httpGet( someuri, { credentialId: xdmp.credentialId('myCredentialName') })
xdmp.httpGet("http://www.my.com/document.xhtml", { "authentication": { "method" : "basic", "username" : "myname", "password" : "mypassword" } }) => the response from the server as well as the specified document
xdmp.httpGet("https://s3.amazonaws.com/marklogic-lambda-us-east-1/", { "authentication": { "method" : "aws4", "username" : "myname", "password" : "mypassword" } }) => the response from the server as well as the specified document
fn.subsequence( xdmp.httpGet("http://www.marklogic.com", { "encoding" : "iso-8859-1" }), 2, 1) => The specified document, transcoded from ISO-8859-1 to UTF-8 encoding. This assumes the document is encoded in ISO-8859-1.