Skip to content

Commit e77b9b2

Browse files
committed
Fix issue about utf-8 and data.class() return undefined
1 parent efecf79 commit e77b9b2

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

demo/app/main-page.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ export function postHttpbin() {
4242
postRequest('https://httpbin.org/post', {"foo": "bar", "baz": undefined, "plaz": null});
4343
}
4444

45+
export function postHttpbinWithUTF8() {
46+
Https.request(
47+
{
48+
url: 'https://httpbin.org/post',
49+
method: 'POST',
50+
body: {"foo": "bar", "baz": undefined, "plaz": null},
51+
headers: {
52+
'Content-Type': "application/json; charset=utf-8"
53+
}
54+
})
55+
.then(response => console.log('Https.request response', response))
56+
.catch(error => {
57+
console.error('Https.request error', error);
58+
dialogs.alert(error);
59+
});
60+
}
61+
4562
export function getHttpbin() {
4663
getRequest('https://httpbin.org/get');
4764
}

demo/app/main-page.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<Button text="GET Httpbin" tap="getHttpbin" class="t-20 btn btn-primary btn-active"/>
1010
<Button text="GET Httpbin (large response)" tap="getHttpbinLargeResponse" class="t-20 btn btn-primary btn-active"/>
1111
<Button text="POST Httpbin " tap="postHttpbin" class="t-20 btn btn-primary btn-active"/>
12+
<Button text="POST Httpbin UTF-8" tap="postHttpbinWithUTF8" class="t-20 btn btn-primary btn-active"/>
1213
<Button text="Httpbin Pinning ON" tap="enableSSLPinning" class="t-20 btn btn-primary btn-active"/>
1314
<Button text="Httpbin Pinning ON, expired cert" tap="enableSSLPinningExpired" class="t-20 btn btn-primary btn-active"/>
1415
<Button text="Httpbin Pinning OFF" tap="disableSSLPinning" class="t-20 btn btn-primary btn-active"/>

src/https.ios.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
137137
return new Promise((resolve, reject) => {
138138
try {
139139
const manager = AFHTTPSessionManager.alloc().initWithBaseURL(NSURL.URLWithString(opts.url));
140-
const contentType = (<string>opts.headers['Content-Type']).substring(0, 16);
141-
if (opts.headers && contentType === 'application/json') {
140+
//const contentType = (<any>opts.headers['Content-Type']).substring(0, 16);
141+
if (opts.headers && (<any>opts.headers['Content-Type']).substring(0, 16) === 'application/json') {
142+
console.log(opts.headers['Content-Type'])
142143
manager.requestSerializer = AFJSONRequestSerializer.serializer();
143144
manager.responseSerializer = AFJSONResponseSerializer.serializerWithReadingOptions(NSJSONReadingOptions.AllowFragments);
144145
} else {

0 commit comments

Comments
 (0)