mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 12:57:42 +08:00
GBK encoding support for http (#3165)
* http response add GBK charset support * default encode do not change * change compare response encode `==` to `===`
This commit is contained in:
@ -65,12 +65,12 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
var headers: http.Headers = {};
|
||||
if (response && response.allHeaderFields) {
|
||||
var headerFields = response.allHeaderFields;
|
||||
|
||||
|
||||
headerFields.enumerateKeysAndObjectsUsingBlock((key, value, stop) => {
|
||||
(<any>http).addHeader(headers, key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (debugRequest) {
|
||||
debugRequest.mimeType = response.MIMEType;
|
||||
debugRequest.data = data;
|
||||
@ -89,9 +89,9 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
resolve({
|
||||
content: {
|
||||
raw: data,
|
||||
toString: () => { return NSDataToString(data); },
|
||||
toJSON: () => {
|
||||
return utils.parseJSON(NSDataToString(data));
|
||||
toString: (encoding?: http.HttpResponseEncoding) => { return NSDataToString(data, encoding); },
|
||||
toJSON: (encoding?: http.HttpResponseEncoding) => {
|
||||
return utils.parseJSON(NSDataToString(data, encoding));
|
||||
},
|
||||
toImage: () => {
|
||||
ensureImageSource();
|
||||
@ -125,7 +125,7 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
}
|
||||
});
|
||||
|
||||
if(options.url && debugRequest) {
|
||||
if (options.url && debugRequest) {
|
||||
var request = {
|
||||
url: options.url,
|
||||
method: "GET",
|
||||
@ -141,6 +141,10 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
});
|
||||
}
|
||||
|
||||
function NSDataToString(data: any): string {
|
||||
return NSString.alloc().initWithDataEncoding(data, 4).toString();
|
||||
function NSDataToString(data: any, encoding?: http.HttpResponseEncoding): string {
|
||||
let code = 4; //UTF8
|
||||
if (encoding === http.HttpResponseEncoding.GBK) {
|
||||
code = 1586;
|
||||
}
|
||||
return NSString.alloc().initWithDataEncoding(data, code).toString();
|
||||
}
|
||||
|
Reference in New Issue
Block a user