views:

40

answers:

1
NSString *urlAddress = @"http://www.test.com/test.jsp?Query=哈囉";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
NSURLResponse* myURLResponse; 
NSError* myError; 
NSData* data = [NSURLConnection sendSynchronousRequest: requestObj returningResponse:&myURLResponse error:& myErr];

I want to use http get method to send request, but failed. English alphabets work well.

I.e., I want to convert "哈囉" to "%E5%93%88%E5%9B%89" so that the response will successfully return. It seems not to be converted by itself automatically.

Anyone could help me solve this problem?

Thanks a lot!

+1  A: 
urlAddress = [urlAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

(docs)

cobbal
Thanks!! work perfectly!