Changes

Jump to navigation Jump to search
524 bytes added ,  15:36, 12 July 2018
This [[Module Library|XQuery Module]] contains a single function to send HTTP requests and handle HTTP responses. The function {{Code|send-request}} is based on the [http://expath.org/spec/http-client EXPath HTTP Client Module]. It gives full control over the available request and response parameters. For simple GET requests, the [[Fetch Module]] may be sufficient.
 
If <code><http:header name="Accept-Encoding" value="gzip"/></code> is specified and if the addressed web server provides support for the {{Code|gzip}} compression algorithm, the response will automatically be decompressed.
=Conventions=
|-
| width='120' | '''Signatures'''
|{{Func|http:send-request|$request as element(http:request)?, $href as xs:string?, $bodies as item()*|item()+}}<br/>{{Func|http:send-request|$request as element(http:request)?, $href as xs:string?|item()+}}<br />{{Func|http:send-request|$request as element(http:request)?, $href as xs:string?, $bodies as item()*|item()+}}<br />
|-
| '''Summary'''
|Sends an HTTP request and interprets the corresponding response. :* {{Code|$request}} contains the parameters of the HTTP request such as HTTP method and headers. * In addition to this it can also contain the URI to which the request will be sent and the body of the HTTP method. * If the URI is not given with the parameter {{Code|$href}}, its value in {{Code|$request}} is used instead.<br/>* The structure request body can also be supplied via the {{Code|$bodies}} parameter. Notes:* Both basic and digest authentication is supported.* While the contents of the request can be supplied as child of the {{Code|http:requestbody}} element follows , it is faster and safer to pass them on via the third argument.* For further information, please check out the [http://expath.org/spec/http-client EXPath] specification. Both basic and digest authentication is supported.
|-
|'''Errors'''
|}
==Examples==
===Status Only===
Simple GET request. As the attribute {{Code|status-only}} is set to true, only the response element is returned.
</http:response></pre>
===Google Homepage=== Retrieve the Google search home pagewith a timeout of 10 seconds. In order to [[http://home.ccil.org/~cowan/XML/tagsoup/ Parsers#HTML_Parser|parse HTML]], TagSoup] must be contained in the class path in order to parse html.
'''Query:'''
<pre class="brush:xquery">http:send-request(<http:request method='get' href='http://www.google.com' timeout='10'/>)</pre>
'''Result:'''
<pre class="brush:xml">
===SVG Data===
 
Content-type ending with +xml, e.g. image/svg+xml.
</svg></pre>
===POST Request=== 
POST request to the BaseX REST Service, specifying a username and password.
=Changelog=
 
;Version 9.0
* Updated: support for gzipped content encoding
;Version 8.0
* Updated: [[#http:send-request|http:send-request]]: {{Code|HC0002}} is raised if the input cannot be parsed or converted to the final data type.
* Updated: errors are using {{Code|text/plain}} as media-type.
 
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu