Dart
Dart
Explaining the Rest ClearResponseBodyStream Method
See more Azure Cloud Storage Examples
The ClearResponseBodyStream method would be needed if your applicaiton called SetResponseBodyStream to send the response to a stream for one request, but then wants to subsequently do something else. The application must call ClearResponseBodyStream to no longer send responses to the stream.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
var success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final rest = CkRest();
// Connect to the web server
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;
}
// Setup a file stream for the download
final fileStream = CkStream();
fileStream.sinkFile = 'qa_output/starfish.jpg';
// Indicate that the call to FullRequestNoBody should send the response body
// to fileStream if the response status code is 200.
// If a non-success response status code is received, then nothing
// is streamed to the output file and the error response is returned by FullRequestNoBody.
final expectedStatus = 200;
rest.setResponseBodyStream(expectedStatus, true, fileStream);
var responseStr = '';
try {
responseStr = rest.fullRequestNoBody('GET', '/images/starfish.jpg');
} on ChilkatException {
// 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('downloaded starfish.jpg');
// Clear the response body stream previously set in the call to SetResponseBodyStream.
rest.clearResponseBodyStream();
// Download something else, but this time send the response body to bd.
final bd = CkBinData();
try {
rest.fullRequestNoBodyBd('GET', '/images/penguins.jpg', bd);
} on ChilkatException {
// 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): ${bd.getString('utf-8')}');
print('---');
print('LastRequestStartLine: ${rest.lastRequestStartLine}');
print('LastRequestHeader: ${rest.lastRequestHeader}');
return;
}
// Save the contents of bd to a file.
success = true;
try {
bd.writeFile('qa_output/penguins.jpg');
} on ChilkatException {
success = false;
}
print('Success: $success');
}