开发者

objective-c accented characters inside a url request

My app connects itself to a server asking for data do a php script and shows these data on a table. When I select a row the datails are shown with the full text. I can read everything correctly on the iPhone and iPad display, but I can modify this text and when I send it to another php script it reads àìùòèé characters not correctly.

The request is sent in this way

NSMutableURLRequest *richiesta = [NSMutableURLRequest requestWithUR开发者_如何学编程L:[NSURL URLWithString:@"http://www.sito.it/iosphp/trame.php"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [richiesta setHTTPMethod:@"POST"]; [richiesta setHTTPBody:[[NSString stringWithFormat:@"trama=%@", self.trama.text] dataUsingEncoding:NSUTF8StringEncoding]];

Inside the database (its collation is UTF8) I see è and other strange things.

How do I manage those characters correctly?


The default Content-Type of a post is application/x-www-form-urlencoded. This means that you need to percent encode the value you are sending over.

[[NSString stringWithFormat:@"trama=%@", [self.trama.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

àìùòèé now becomes %C3%A0%C3%AC%C3%B9%C3%B2%C3%A8%C3%A9

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜