|
|
xdmp:get-request-body(
|
|
[$format as xs:string]
|
| ) as item()* |
|
 |
Summary:
Returns the POST or PUT body of this request, if it is not
application/x-www-form-urlencoded.
Returns the empty sequence if it is not called from an application
server.
|
Parameters:
$format
(optional):
The format ("xml", "text", or "binary") to interpret the body as. If not supplied,
the format associated with the content-type header in Mimetypes.xml is used. If no
content-type header exists, the default format is "binary".
|
|
Usage Notes:
If the content-type of the POST or PUT body is application/x-www-form-urlencoded,
it is not available here, but instead is available in its decoded form
through xdmp:get-request-field-names() and
xdmp:get-request-field().
If there is no content-type header in the request, then the request
body defaults to application/x-www-form-urlencoded, and therefore
xdmp:get-request-body will return the empty sequence. If
you want to read the request body, then the POST must include a
content-type header.
You can use this function to process certain types of web service
SOAP requests with MarkLogic Server.
The output of an xdmp:get-request-body call is
typically a document node, so if you want to get the contents of
the POST, you should add a /node() XPath step to
the output. The contents of the document node could be a a text node,
a document node, or a binary node.
|
Example:
xdmp:get-request-body()/node()
=> "<a>Contents of POST body.</a>"
|
|
|
|
xdmp:get-request-client-address( ) as xs:string?
|
|
 |
Summary:
Returns as a string the internet address of the
client from which the HTTP server request is issued.
Returns the empty sequence if it is not called from an HTTP server.
|
Usage Notes:
Use this function if you need to get the internet protocol (IP) address of
the requesting client. For example, you can create an application that
contains conditional code based on IP addresses (see the example below).
|
Example:
The following example shows logic which checks if the request was
submitted from the "localhost" IP address (127.0.0.1).
if (xdmp:get-request-client-address() eq "127.0.0.1")
then "Submitted from localhost."
else "Only localhost access is allowed for this application."
|
Example:
xdmp:get-request-client-address()
=> "127.0.0.1"
|
|
|
|
xdmp:get-request-field(
|
|
$name as xs:string,
|
|
[$default as xs:string]
|
| ) as xs:string* |
|
 |
Summary:
Returns the value of a named request field. If the request field
is a multipart/form-data type in a POST form, you can
use xdmp:get-request-field for file upload applications
(see the second example below).
|
Parameters:
$name
:
Request field name.
|
$default
(optional):
A default value to return if there is no request field.
|
|
Example:
xdmp:get-request-field("index")
=> "10"
|
Example:
Consider a form.xqy XQuery module with the following content:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form name="test" action="upload.xqy?uid={xdmp:random()}" method="post"
enctype="multipart/form-data">
<p><label>File to upload:
<input type="file" class="name" name="upload" size="50"/></label></p>
<p><input type="submit" value="Upload and Get Results"/></p>
</form>
</body>
</html>
Then have an upload.xqy XQuery module as follows:
let $filename := xdmp:get-request-field-filename("upload")
let $disposition := fn:concat("attachment; filename=""",$filename,"""")
let $x := xdmp:add-response-header("Content-Disposition", $disposition)
let $x:= xdmp:set-response-content-type(
xdmp:get-request-field-content-type("upload"))
return
xdmp:get-request-field("upload")
Execute the form.xqy file, select a file, and click the
"Upload and Get Results" button. The file you uploaded
will open according to the mime type the browser. If you
wanted to save it to the database, you could use
xdmp:document-insert to do so.
|
|
|
|
xdmp:login(
|
|
$name as xs:string,
|
|
[$password as xs:string?],
|
|
[$set-session as xs:boolean]
|
| ) as xs:boolean |
|
 |
Summary:
Logs in a user on an application server that is using
application-level authentication and deposits a session cookie.
Returns true on success, false on failure.
If the user calling this function has the xdmp:login
privilege, this function can be called without a password or with the empty
sequence as the password. In this case, login will succeed if
the specified user exists. Therefore, use the xdmp:login
privilege carefully, as any user with that
privilege will be able to execute code that uses the xdmp:login
function to log in as any user.
|
Parameters:
$name
:
The username of the user to be logged in.
|
$password
(optional):
The user's password. The password is not needed if the user
calling the function has the xdmp:login execute privilege.
|
$set-session
(optional):
A boolean value specifying whether to set a session variable for the
login. The default is true. Set to false to not set the
session variable to maintain the user logged in.
|
|
Example:
xdmp:login("mark","secret")
=> true() -- if user "mark" has password "secret"
|
Example:
xdmp:login("username") or xdmp:login("username", ())
=> true() -- if user calling the function has the
xdmp:login privilege
|
Example:
xdmp:login("username") or xdmp:login("username", ())
=> SEC-PRIV exception if the user calling the function does
not have the xdmp:login privilege
|
Example:
xdmp:login("username")
=> true() -- if current user has the xdmp:login privilege
|
Example:
xdmp:login("username")
=> SEC-PRIV exception if current user does not have the
xdmp:login privilege
|
|
|