1-
21import * as Observable from 'tns-core-modules/data/observable'
32import * as Page from 'tns-core-modules/ui/page'
43import * as fs from 'tns-core-modules/file-system'
54import * as dialogs from 'tns-core-modules/ui/dialogs'
65import * as Https from 'nativescript-https'
76
8-
9-
107export function onNavigatingTo ( args : Page . NavigatedData ) {
118 let page = args . object as Page . Page
129 page . bindingContext = Observable . fromObject ( { enabled : false } )
1310}
1411
15- function getRequest ( url : string ) {
12+ function getRequest ( url : string , allowLargeResponse = false ) {
13+ Https . request ( {
14+ url,
15+ method : 'GET' ,
16+ allowLargeResponse
17+ } ) . then ( function ( response ) {
18+ console . log ( 'Https.request response' , response )
19+ } ) . catch ( function ( error ) {
20+ console . error ( 'Https.request error' , error )
21+ dialogs . alert ( error )
22+ } )
23+ }
24+
25+ function postRequest ( url : string , body : any ) {
1626 Https . request ( {
17- url, method : 'GET' ,
27+ url,
28+ method : 'POST' ,
29+ body
1830 } ) . then ( function ( response ) {
1931 console . log ( 'Https.request response' , response )
2032 } ) . catch ( function ( error ) {
@@ -23,7 +35,9 @@ function getRequest(url: string) {
2335 } )
2436}
2537
38+ export function postHttpbin ( ) { postRequest ( 'https://httpbin.org/post' , { "foo" : "bar" , "baz" : undefined , "plaz" : null } ) }
2639export function getHttpbin ( ) { getRequest ( 'https://httpbin.org/get' ) }
40+ export function getHttpbinLargeResponse ( ) { getRequest ( 'https://httpbin.org/bytes/100000' , true ) }
2741export function getMockbin ( ) { getRequest ( 'https://mockbin.com/request' ) }
2842
2943export function enableSSLPinning ( args : Observable . EventData ) {
0 commit comments