发送带有中文字词的http请求 [英] Send http request with Chinese words

查看:47
本文介绍了发送带有中文字词的http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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];

我想使用http get方法发送请求,但是失败.英文字母效果很好.

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

即,我要将哈啰"转换为%E5%93%88%E5%9B%89",以便成功返回响应.看来它不会自动转换.

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?

非常感谢!

推荐答案

urlAddress = [urlAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

( 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆