send method
void
send([
- dynamic bodyOrData
Send the request with any given data.
Note: Most simple HTTP requests can be accomplished using the getString,
request, requestCrossOrigin, or postFormData methods. Use of this
send method is intended only for more complex HTTP requests where
finer-grained control is needed.
Other resources
- XMLHttpRequest.send from MDN.
Implementation
void send([dynamic bodyOrData]) {
// Read request body
Uint8List? data;
if (bodyOrData != null) {
if (bodyOrData is String) {
data = Uint8List.fromList(utf8.encode(bodyOrData));
} else if (bodyOrData is Uint8List) {
data = bodyOrData;
} else {
throw ArgumentError.value(bodyOrData);
}
}
// Get internal request ID
_requestId++;
final requestId = _requestId;
// Reset response fields
_status = 0;
_statusText = '';
_responseHeaders.clear();
_responseData = null;
// Send
_send(requestId, data);
}