mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
wip: switch core http to okhttp
This commit is contained in:
29
apps/toolbox/src/pages/http.ts
Normal file
29
apps/toolbox/src/pages/http.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
6
apps/toolbox/src/pages/http.xml
Normal file
6
apps/toolbox/src/pages/http.xml
Normal 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>
|
||||
Reference in New Issue
Block a user