ajax function
Sends an Ajax request to the given url and returns the response.
Same semantics as package:http's top-level functions (http.get,
http.put, …): body is buffered into the returned http.Response.
Pass bytes via data or a string via body.
Don't set Content-Length in headers — it's auto-computed from
the encoded body.
-
timeoutbounds the entire request — connect, send, response, and body read. If exceeded, the underlying HttpClient is force-closed (releasing the socket immediately) and TimeoutException is thrown.package:http's top-level functions cannot do this — they construct an internalClientand give no handle to force-close. -
maxLengthcaps the response body, in bytes. If exceeded, reading stops and HttpException is thrown — e.g., so a compromised third party can't exhaust the memory with a huge response. A largerContent-Lengthis rejected before reading the body.
Implementation
Future<http.Response> ajax(Uri url, {String method = "GET",
List<int>? data, String? body, Map<String, String>? headers,
Duration? timeout, int? maxLength})
=> _ajax(url, method: method, data: data, body: body, headers: headers,
timeout: timeout, getResponse: maxLength == null ?
http.Response.fromStream: (resp) => _responseFromStream(resp, maxLength));