FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(ios-http-get): http failure during parsing xml (#7175) · NativeScript/NativeScript@c227c50 · GitHub

Commit c227c50

Browse files
authored andcommitted
fix(ios-http-get): http failure during parsing xml (#7175)
1 parent 4b16363 commit c227c50

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎tns-core-modules/http/http-request/http-request.ios.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,21 @@ export function request(options: httpModule.HttpRequestOptions): Promise<httpMod
200200
}
201201

202202
function NSDataToString(data: any, encoding?: HttpResponseEncoding): string {
203-
let code = 4; //UTF8
203+
let code = NSUTF8StringEncoding; // long:4
204+
204205
if (encoding === HttpResponseEncoding.GBK) {
205-
code = 1586;
206+
code = CFStringEncodings.kCFStringEncodingGB_18030_2000; // long:1586
206207
}
207-
return NSString.alloc().initWithDataEncoding(data, code).toString();
208+
209+
let encodedString = NSString.alloc().initWithDataEncoding(data, code);
210+
211+
// If UTF8 string encoding fails try with ISO-8859-1
212+
if (!encodedString) {
213+
code = NSISOLatin1StringEncoding; // long:5
214+
encodedString = NSString.alloc().initWithDataEncoding(data, code);
215+
}
216+
217+
return encodedString.toString();
208218
}
209219

210220
export function addHeader(headers: httpModule.Headers, key: string, value: string): void {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL