Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Modification: when the url contained in the Chinese, MKNetworkOperation instantiation is not successful #377

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions MKNetworkKit/MKNetworkOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,29 @@ -(void) addDownloadStream:(NSOutputStream*) outputStream {
[self.downloadStreams addObject:outputStream];
}

//xieyajie add 2013-08-19
#define IS_CH_SYMBOL(chr) ((int)(chr)>127)

- (BOOL)isHaveChinese:(NSString *)string
{
// for (int i = 0; i < [string length]; i++) {
// unichar ch = [string characterAtIndex:i];
// if(IS_CH_SYMBOL(ch)== 1)
// {
// return YES;
// }
// }
//
// return NO;

const char *cString = [string UTF8String];
if (strlen(cString) == [string length]) {
return NO;
}
return YES;
}
//end

- (id)initWithURLString:(NSString *)aURLString
params:(NSDictionary *)params
httpMethod:(NSString *)method
Expand All @@ -634,8 +657,18 @@ - (id)initWithURLString:(NSString *)aURLString

if(params)
self.fieldsToBePosted = [params mutableCopy];

//xieyajie edit 2013-08-19
if ([self isHaveChinese:aURLString]) {
self.stringEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
}
else{
self.stringEncoding = NSUTF8StringEncoding; // use a delegate to get these values later
}

self.stringEncoding = NSUTF8StringEncoding; // use a delegate to get these values later
// self.stringEncoding = NSUTF8StringEncoding; // use a delegate to get these values later

//end

if(!method) method = @"GET";

Expand All @@ -648,7 +681,8 @@ - (id)initWithURLString:(NSString *)aURLString
finalURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", aURLString,
[self.fieldsToBePosted urlEncodedKeyValueString]]];
} else {
finalURL = [NSURL URLWithString:aURLString];
// finalURL = [NSURL URLWithString:aURLString];
finalURL = [NSURL URLWithString:[aURLString stringByAddingPercentEscapesUsingEncoding: self.stringEncoding]];
}

if(finalURL == nil) {
Expand Down