Dart
Dart
Get a REST Response Header Value by Index
See more REST Examples
Demonstrates Rest.ResponseHdrValue, which returns the value of the response header at a zero-based index. The same index used with ResponseHdrName gives the corresponding field name.
Background. Response headers can be enumerated by index from 0 through NumResponseHeaders minus one, after ReadResponseHeader has been called.
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;
}
try {
rest.sendReqNoBody('GET', '/api/items/123');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final statusCode = rest.readResponseHeader();
if (statusCode < 0) {
print(rest.lastErrorText);
return;
}
// Return the value of the response header at a zero-based index. Use the same index with
// ResponseHdrName to get the corresponding field name.
final numHeaders = rest.numResponseHeaders;
for (var i = 0; i < numHeaders; i++) {
final String value;
try {
value = rest.responseHdrValue(i);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Header $i value: $value');
}
}