send method

Future<Response> send(
  1. dynamic data
)

Implementation

Future<http.Response> send(var data) {
  var self = this;
  try {
    if (method == 'GET') {
      _logger.fine('FlutterHttpRequest ${method} ${url}');
      future = http.get(Uri.parse(url!), headers: headers);
    } else if (method == 'POST') {
      _logger.fine('FlutterHttpRequest ${method} ${url} ${data}');
      future = http.post(Uri.parse(url!), headers: headers, body: data);
    }
    future?.then((response) {
      if (response.headers['set-cookie'] != null) {
        headers['cookie'] = response.headers['set-cookie'] ?? '';
      }
      responseText = response.body;
      status = response.statusCode;
      _logger.fine(
          'FlutterHttpRequest ${method} ${status} ${url} ${data} ${responseText}');
      Map event = {'target': self};
      readyState = 2;
      responseHeaders = response.headers;
      onReadyStateChange.listener!(event);
      if (responseType == 'arraybuffer') {
        this.response = response.bodyBytes.buffer;
      }
      readyState = 4;
      onReadyStateChange.listener!(event);
    });
    return future!;
  } catch (e) {
    onerror(e);
    return future!;
  }
}