Dart
Dart
Send a Form-URL-Encoded REST Request
See more REST Examples
Demonstrates Rest.FullRequestFormUrlEncoded, which sends an application/x-www-form-urlencoded request. The body is built from the query parameters added to the object, and the response body is returned as text.
Background. For a form-url-encoded request the accumulated parameters become the request body rather than the URL query string. This matches the encoding used by HTML form POSTs.
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;
}
// The application/x-www-form-urlencoded body is built from the query parameters added to the object.
rest.addQueryParam('username', 'alice');
rest.addQueryParam('action', 'login');
// Send the form-url-encoded request. The parameters become the request body rather than the URL
// query string.
final String responseText;
try {
responseText = rest.fullRequestFormUrlEncoded('POST', '/api/login');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print(responseText);
}