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.
Please note that BaseX provides extensions to the specification:
* Since {{Announce|Version 11}}, {{Code|csv}}, {{Code|json}} and {{Code|html}} parser options can be supplied to influence the conversion of the response.
Since BaseX 10, the module is based on the [https://openjdk.org/groups/net/httpclient/intro.html Java HTTP Client], which provides a better overall performance, uses internal connection pools and follows redirects across different protocols (http, https).
=Conventions=
==http:send-request==
{{Announce|Updated with Version 11:}} {{Code|csv}}, {{Code|json}}, {{Code|html}} and {{Code|text}} attributes added.
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|http:send-request|$request as element(http:request)|item()+}}<br /pre>{{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()*| := ()) as item()+}}<br/pre>
|- valign="top"
| '''Summary'''
|Sends an HTTP request and interprets the corresponding response:
* {{Code|$request}} contains the parameters of the HTTP an {{Code|<http:request such as HTTP />}} element with a {{Code|method }} attribute, an {{Code|href}} attribute with the target URI, and optional header and headersbody elements.* In addition The request is either sent to this it can also contain the URI of the {{Code|$href}} argument or (if empty) to which the request will be sent and URI supplied via the body of the HTTP method{{Code|href}} attribute.* If In addition to the URI is not given with attributes of the parameter official specification, {{Code|$hrefcsv}}, its value in {{Code|$requestjson}} is used instead.* The request body can also be supplied via the , {{Code|$bodieshtml}} parameter.* Certificate verification can be globally disabled via the and {{OptionCode|IGNORECERTtext}} optionattributes can be supplied to define how to convert the response body (see [[#Response Conversion|Response Conversion]] for an example).
Notes:
* Both basic and digest authentication is supported.
* While the contents of the request can be supplied as child of the {{Code|http:body}} element, it is faster and safer to pass them on via the third argument.
* Certificate verification can be globally disabled via the {{Option|IGNORECERT}} option.
* For further information, please check out the [http://expath.org/spec/http-client EXPath] specification.
|- valign="top"
==Status Only==
Simple GET request. As the attribute {{Code|status-only}} is set to true, only the response element is returned.
'''Query:'''
<syntaxhighlight pre lang="'xquery"'>http:send-request(<http:request method='get' status-only='true'/>, 'http://basex.org')</syntaxhighlightpre>
'''Result:'''
<syntaxhighlight pre lang="xml"><http:response status="200" message="OK">
<http:header name="Date" value="Mon, 14 Mar 2011 20:55:53 GMT"/>
<http:header name="Content-Length" value="12671"/>
<http:header name="Cache-Control" value="max-age=90"/>
<http:body media-type="text/html; charset=utf-8"/>
</http:response></syntaxhighlightpre>
==Google Homepage==
Retrieve the Google search home page with a timeout of 10 seconds. In order to [[Parsers#HTML_ParserHTMLParser|parse HTML]], TagSoup must be contained in the class path.
'''Query:'''
<syntaxhighlight pre lang="'xquery"'>http:send-request(<http:request method='get' href='http://www.google.com' timeout='10'/>)</syntaxhighlightpre>
'''Result:'''
<syntaxhighlight pre lang="xml">
<http:response status="200" message="OK">
<http:header name="Date" value="Mon, 14 Mar 2011 22:03:25 GMT"/>
</body>
</html>
</syntaxhighlightpre>
The response content type can also be overwritten in order to retrieve HTML pages and other textual data as plain string (using {{Code|text/plain}}) or in its binary representation (using {{Code|application/octet-stream}}). With the {{Code|http:header}} element, a custom user agent can be set. See the following example:
'''Query:'''
<syntaxhighlight pre lang="'xquery"'>
let $binary := http:send-request(
<http:request method='get'
'Conversion to XML failed: ' || $err:description
}
</syntaxhighlightpre>
===SVG Data===
'''Query:'''
<syntaxhighlight pre lang="'xquery"'>http:send-request(<http:request method='get'/>, 'http://upload.wikimedia.org/wikipedia/commons/6/6b/Bitmap_VS_SVG.svg')</syntaxhighlightpre>
'''Result:'''
<syntaxhighlight pre lang="xml"><http:response status="200" message="OK">
<http:header name="ETag" value="W/"11b6d-4ba15ed4""/>
<http:header name="Age" value="9260"/>
</linearGradient>
...
</svg></syntaxhighlightpre>
==POST Request==
'''Query:'''
<syntaxhighlight pre lang="'xquery"'>
http:send-request(
<http:request method='post' username='admin' password='admin'>
</query>
)
</syntaxhighlightpre>
'''Result:'''
<syntaxhighlight pre lang="xml">
<http:response xmlns:http="http://expath.org/ns/http-client" status="200" message="OK">
<http:header name="Content-Length" value="135"/>
<div>Section 3</div>
</html>
</syntaxhighlightpre>
==File Upload==
'''Query:'''
<syntaxhighlight pre lang="'xquery"'>
let $path := 'file-to-be.uploaded'
return http:send-request(
file:read-binary($path)
)
</syntaxhighlightpre>
'''RESTXQ service:'''
<syntaxhighlight pre lang="'xquery"'>
declare
%rest:POST
});
};
</syntaxhighlightpre> ==Response Conversion== CSV, JSON and HTML responses are automatically converted to an XML representation. The target format can be influenced by supplying {{Code|csv}}, {{Code|json}} and {{Code|html}} attributes: '''Query:''' <pre lang='xquery'>http:send-request(<http:request method='GET' href='http://localhost:8080/json' json='format=xquery,lax=true'/>)</pre> '''Result:'''<pre lang="javascript">map { "abcde": 12345 }</pre> Without the {{Code|json}} attribute, the response body is converted to the default XML representation: <pre lang="xml"><json type="object"> <abcde>12345</abcde></json></pre> '''RESTXQ service:''' <pre lang='xquery'>declare %rest:path('json') %output:method('json')function local:json() { map { 'abcde': 12345 }};</pre> See the [[CSV Module]], [[JSON Module]] and [[HTML Module]] for a list of the available options.
=Errors=
=Changelog=
;Version 11.0
* Updated: {{Function||http:send-request}}: {{Code|csv}}, {{Code|json}}, {{Code|html}} and {{Code|text}} attributes added.
;Version 10.0
* Updated: Implementation based on the new [https://openjdk.org/groups/net/httpclient/intro.html Java HTTP Client].
;Version 9.0