TsgcHTTP3Client › Methods › Query
Sends a synchronous HTTP/3 QUERY request, a safe and idempotent verb that carries a request body.
function Query(const aURL: string; const aData: string;
const aContentType: string = 'application/x-www-form-urlencoded'): string; overload;
| Name | Type | Description |
|---|---|---|
aURL | const string | Absolute URL of the target resource. |
aData | const string | Request body. It is encoded as UTF-8 before being sent in the HTTP/3 DATA frame. |
aContentType | const string | Value of the content-type request header. Defaults to application/x-www-form-urlencoded. |
Response body received from the server, decoded as a string. (string)
procedure Query(const aURL: string; const aSource: TStream;
const aResponseContent: TStream); overload;
| Name | Type | Description |
|---|---|---|
aURL | const string | Absolute URL of the target resource. |
aSource | TStream | Stream read in full from position 0 and sent as the request body. May be nil to send an empty body. |
aResponseContent | TStream | Stream that receives the response body. |
None. The response body is written to aResponseContent.
The call blocks the calling thread until the complete response has been received. When the client is not connected yet, the URL is used to open the QUIC connection first. For a non-blocking request use QueryAsync, which delivers the reply on OnResponse.
QUERY is the IETF HTTP QUERY method. It behaves like Get in that it is safe and idempotent and only asks the server for data, but unlike GET it carries a request body. That makes it the right verb for search and filter operations whose criteria are too large or too structured to fit in a query string, and which would otherwise be forced onto Post and lose cacheability.
The string overload encodes aData as UTF-8 and defaults aContentType to application/x-www-form-urlencoded. The stream overload always sends content-type: application/octet-stream. It does not accept an aContentType parameter, so when the server requires a specific media type use the string overload instead.
QUERY is a recent addition to HTTP, so confirm the target server implements it before relying on it. A server that does not recognise the method normally answers 405 Method Not Allowed or 501 Not Implemented.
vBody := '{"filter": {"city": "Madrid"}}';
vResponse := oClient.Query('https://api.example.com/v1/search', vBody,
'application/json');