Dart
Dart
REST Auto Reconnect for Multiple Requests (dev.markitondemand.com)
See more REST Examples
Demonstrates how the autoReconnect argument to the Connect method is used.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 demonstrates the usage of the autoReconnect argument to the Connect method.
// When autoReconnect is on, subsequent REST method calls will automatically re-connect
// if necessary, using the same information (domain/IP address, port number, and TLS).
final bTls = false;
final port = 80;
final bAutoReconnect = true;
rest.connect('dev.markitondemand.com', port, bTls, bAutoReconnect);
// Get a stock quote:
rest.addQueryParam('symbol', 'AAPL');
String responseXml;
try {
responseXml = rest.fullRequestNoBody('GET', '/MODApis/Api/v2/Quote');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final xml = CkXml();
xml.loadXml(responseXml);
print('AAPL LastPrice: ${xml.getChildContent('LastPrice')}');
// Get another stock quote. If a new HTTP connection is required,
// the REST object will automatically connect using the same parameters.
rest.addQueryParam('symbol', 'AMZN');
try {
responseXml = rest.fullRequestNoBody('GET', '/MODApis/Api/v2/Quote');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
xml.loadXml(responseXml);
print('AMZN LastPrice: ${xml.getChildContent('LastPrice')}');
}