React Native
React Native
Example: Http.DownloadSb method
See more HTTP Examples
Demonstrates theDownloadSb method.
Chilkat React Native Downloads
import { Http, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
let success = false;
const http = new Http();
http.keepResponseBody = true;
const sb = new StringBuilder();
success = true;
try {
await http.downloadSbAsync('https://chilkatsoft.com/testData/helloWorld.txt', 'utf-8', sb);
} catch {
success = false;
}
const statusCode = http.lastStatus;
if (!success) {
if (statusCode === 0) {
// Unable to either send the request or get the response.
console.log(http.lastErrorText);
} else {
// We got a response, but the status code was not in the 200s
console.log(`Response status code: ${statusCode}`);
// Examine the response body.
console.log('Response body:');
console.log(http.lastResponseBody);
}
console.log('Download failed.');
} else {
console.log(`Download success, response status = ${statusCode}`);
console.log(sb.getAsString());
}
}