From 9f291886da0a4c093e1f70bff0fa7e3a4544dcf6 Mon Sep 17 00:00:00 2001 From: kefahB Date: Sat, 18 Jan 2020 20:54:09 +0100 Subject: [PATCH 01/14] fix issue #56 data.class() return undefined data.class() return undefined => use data `instanceof` instead --- src/https.ios.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/https.ios.ts b/src/https.ios.ts index 0c4bed5..1d9770c 100644 --- a/src/https.ios.ts +++ b/src/https.ios.ts @@ -44,7 +44,7 @@ function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary Date: Sat, 18 Jan 2020 20:56:29 +0100 Subject: [PATCH 02/14] Update package.json --- src/package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/package.json b/src/package.json index 13b9002..a906fef 100644 --- a/src/package.json +++ b/src/package.json @@ -43,7 +43,13 @@ "name": "Robert Laverty", "email": "roblav96@gmail.com", "url": "https://github.com/roblav96" + }, + { + "name": "Kefah BADER ALDIN", + "email": "kefah.bader@gmail.com", + "url": "https://github.com/kefahB" } + ], "repository": "github:gethuman/nativescript-https", "homepage": "https://github.com/gethuman/nativescript-https", From 0951fd06b5addd16313adb3b3635bff53077438b Mon Sep 17 00:00:00 2001 From: kefahB Date: Sat, 18 Jan 2020 21:38:24 +0100 Subject: [PATCH 03/14] Typescript fix --- src/https.ios.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/https.ios.ts b/src/https.ios.ts index 1d9770c..937469d 100644 --- a/src/https.ios.ts +++ b/src/https.ios.ts @@ -44,7 +44,7 @@ function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary(data) instanceof NSArray) { // content = {} // data.enumerateKeysAndObjectsUsingBlock(function(k, v) { // console.log('v.description', v.description) @@ -53,7 +53,7 @@ function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary(data) instanceof NSData) { content = NSString.alloc().initWithDataEncoding(data, NSASCIIStringEncoding).toString(); // } else if (data.class().name == 'NSArray') { // content = [] From 847ddabe63d70e6dfb6139d0c6223fdbc59fc1bd Mon Sep 17 00:00:00 2001 From: kefahB Date: Sat, 18 Jan 2020 21:49:16 +0100 Subject: [PATCH 04/14] Update https.ios.ts --- src/https.ios.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/https.ios.ts b/src/https.ios.ts index 937469d..cd45551 100644 --- a/src/https.ios.ts +++ b/src/https.ios.ts @@ -44,7 +44,7 @@ function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary(data) instanceof NSArray) { + if (data.enumerateKeysAndObjectsUsingBlock || (data) instanceof NSArray) { // content = {} // data.enumerateKeysAndObjectsUsingBlock(function(k, v) { // console.log('v.description', v.description) @@ -53,7 +53,7 @@ function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary(data) instanceof NSData) { + } else if ((data) instanceof NSData) { content = NSString.alloc().initWithDataEncoding(data, NSASCIIStringEncoding).toString(); // } else if (data.class().name == 'NSArray') { // content = [] From 42c17d207de8d6547ac311d511f429a833948cb4 Mon Sep 17 00:00:00 2001 From: kefahB Date: Thu, 23 Jan 2020 15:37:42 +0100 Subject: [PATCH 05/14] Authorize utf-8 to be set on Content-Type related with #54 --- src/https.ios.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/https.ios.ts b/src/https.ios.ts index cd45551..220011a 100644 --- a/src/https.ios.ts +++ b/src/https.ios.ts @@ -138,10 +138,12 @@ export function request(opts: Https.HttpsRequestOptions): Promise Date: Thu, 23 Jan 2020 15:42:49 +0100 Subject: [PATCH 06/14] Update https.ios.ts --- src/https.ios.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/https.ios.ts b/src/https.ios.ts index 220011a..e24004a 100644 --- a/src/https.ios.ts +++ b/src/https.ios.ts @@ -136,11 +136,8 @@ function AFFailure(resolve, reject, task: NSURLSessionDataTask, error: NSError) export function request(opts: Https.HttpsRequestOptions): Promise { return new Promise((resolve, reject) => { try { - const manager = AFHTTPSessionManager.alloc().initWithBaseURL(NSURL.URLWithString(opts.url)); - let contentType = opts.headers['Content-Type'].substring(0, 16); - if (opts.headers && contentType === 'application/json') { manager.requestSerializer = AFJSONRequestSerializer.serializer(); manager.responseSerializer = AFJSONResponseSerializer.serializerWithReadingOptions(NSJSONReadingOptions.AllowFragments); From 1961e5e8bbbb67f8ea6ad8e9b6f76f4b50f68a22 Mon Sep 17 00:00:00 2001 From: kefahB Date: Thu, 23 Jan 2020 15:52:49 +0100 Subject: [PATCH 07/14] Update https.ios.ts --- src/https.ios.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/https.ios.ts b/src/https.ios.ts index e24004a..867540b 100644 --- a/src/https.ios.ts +++ b/src/https.ios.ts @@ -137,7 +137,8 @@ export function request(opts: Https.HttpsRequestOptions): Promise { try { const manager = AFHTTPSessionManager.alloc().initWithBaseURL(NSURL.URLWithString(opts.url)); - let contentType = opts.headers['Content-Type'].substring(0, 16); + + let contentType = (opts.headers['Content-Type']).substring(0, 16); if (opts.headers && contentType === 'application/json') { manager.requestSerializer = AFJSONRequestSerializer.serializer(); manager.responseSerializer = AFJSONResponseSerializer.serializerWithReadingOptions(NSJSONReadingOptions.AllowFragments); From efecf79d5cb7b70982dd4fe2e6387172db365afb Mon Sep 17 00:00:00 2001 From: kefahB Date: Thu, 23 Jan 2020 16:01:08 +0100 Subject: [PATCH 08/14] Update https.ios.ts --- src/https.ios.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/https.ios.ts b/src/https.ios.ts index 867540b..03b40c8 100644 --- a/src/https.ios.ts +++ b/src/https.ios.ts @@ -137,8 +137,7 @@ export function request(opts: Https.HttpsRequestOptions): Promise { try { const manager = AFHTTPSessionManager.alloc().initWithBaseURL(NSURL.URLWithString(opts.url)); - - let contentType = (opts.headers['Content-Type']).substring(0, 16); + const contentType = (opts.headers['Content-Type']).substring(0, 16); if (opts.headers && contentType === 'application/json') { manager.requestSerializer = AFJSONRequestSerializer.serializer(); manager.responseSerializer = AFJSONResponseSerializer.serializerWithReadingOptions(NSJSONReadingOptions.AllowFragments); From e77b9b2d9a6e0844a200f9af65e0e425beed6af5 Mon Sep 17 00:00:00 2001 From: "kefah@Cocarz" Date: Thu, 6 Feb 2020 22:02:33 +0100 Subject: [PATCH 09/14] Fix issue about utf-8 and data.class() return undefined --- demo/app/main-page.ts | 17 +++++++++++++++++ demo/app/main-page.xml | 1 + src/https.ios.ts | 5 +++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts index 3944f11..9405437 100644 --- a/demo/app/main-page.ts +++ b/demo/app/main-page.ts @@ -42,6 +42,23 @@ export function postHttpbin() { postRequest('https://httpbin.org/post', {"foo": "bar", "baz": undefined, "plaz": null}); } +export function postHttpbinWithUTF8() { + Https.request( + { + url: 'https://httpbin.org/post', + method: 'POST', + body: {"foo": "bar", "baz": undefined, "plaz": null}, + headers: { + 'Content-Type': "application/json; charset=utf-8" + } + }) + .then(response => console.log('Https.request response', response)) + .catch(error => { + console.error('Https.request error', error); + dialogs.alert(error); + }); + } + export function getHttpbin() { getRequest('https://httpbin.org/get'); } diff --git a/demo/app/main-page.xml b/demo/app/main-page.xml index 7ccb009..25c7df0 100644 --- a/demo/app/main-page.xml +++ b/demo/app/main-page.xml @@ -9,6 +9,7 @@