Dart
Dart
Send a Multipart REST Request
See more REST Examples
Demonstrates Rest.FullRequestMultipart, which sends a complete multipart request using the parts configured on the object, then returns the response body as text.
Background. Each multipart part is built by selecting it with the part selector, adding its header fields, and setting its body. FullRequestMultipart then assembles and sends all configured parts as a single multipart request.
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
final rest = CkRest();
final bTls = true;
final bAutoReconnect = true;
try {
rest.connect('example.com', 443, bTls, bAutoReconnect);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Configure a multipart request part before sending. PartSelector selects the part being built,
// and the header fields and body apply to that part.
rest.partSelector = '1';
rest.addHeader('Content-Type', 'text/plain');
rest.addHeader('Content-Disposition', 'form-data; name="field1"');
try {
rest.setMultipartBodyString('value1');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Send the multipart request using the configured parts. The response body is returned as text.
final String responseText;
try {
responseText = rest.fullRequestMultipart('POST', '/api/upload');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print(responseText);
}