wip: switch core http to okhttp

This commit is contained in:
Eduardo Speroni
2022-10-27 13:52:49 -03:00
parent e2c2f1f4a6
commit 1b25f7e3b5
7 changed files with 6117 additions and 44 deletions

View File

@@ -0,0 +1,29 @@
import { Page, EventData, Application, File, Folder, knownFolders, path, getFileAccess, Utils, Http } from '@nativescript/core';
import { AbortController } from '@nativescript/core/abortcontroller';
let page: Page;
export function navigatingTo(args: EventData) {
page = <Page>args.object;
}
export async function makeRequest(args) {
try {
// const result = await fetch('https://httpbin.org/get');
const controller = new AbortController();
console.log('getting json with okhttp!');
// const result = await Http.getJSON('https://httpbin.org/get')
setTimeout(() => {
controller.abort();
}, 0);
const result = await Http.request({
method: 'GET',
url: 'https://httpbin.org/get',
signal: controller.signal as any,
});
console.log(result);
} catch (e) {
console.log(e.stack);
}
}

View File

@@ -0,0 +1,6 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
<StackLayout>
<Button text="Make request" tap="makeRequest" />
</StackLayout>
</Page>