Dart
Dart
POST application/x-www-form-urlencoded using REST API
See more REST Examples
Demonstrates how to send a POST with query params (x-www-form-urlencoded) using the Chilkat REST object.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final rest = CkRest();
// This example will send to https://www.chilkatsoft.com/echoPost.asp
// Make the initial connection (without sending a request yet).
final bTls = true;
final port = 443;
final bAutoReconnect = true;
try {
rest.connect('www.chilkatsoft.com', port, bTls, bAutoReconnect);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Provide query params.
rest.addQueryParam('firstName', 'John');
rest.addQueryParam('lastName', 'Doe');
rest.addQueryParam('company', 'Bisco Bits Ltd.');
final String responseStr;
try {
responseStr = rest.fullRequestFormUrlEncoded('POST', '/echoPost.asp');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// When successful, the response status code will equal 200.
if (rest.responseStatusCode != 200) {
// Examine the request/response to see what happened.
print('response status code = ${rest.responseStatusCode}');
print('response status text = ${rest.responseStatusText}');
print('response header: ${rest.responseHeader}');
print('response body (if any): $responseStr');
print('---');
print('LastRequestStartLine: ${rest.lastRequestStartLine}');
print('LastRequestHeader: ${rest.lastRequestHeader}');
return;
}
print(responseStr);
print('Success.');
}