ajax function

Future<Response> ajax(
  1. Uri url, {
  2. String method = "GET",
  3. List<int>? data,
  4. String? body,
  5. Map<String, String>? headers,
  6. Duration? timeout,
  7. int? maxLength,
})

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.

  • timeout bounds 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 internal Client and give no handle to force-close.

  • maxLength caps 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 larger Content-Length is 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));