NSData 到 NSString 使用 åöä
我正在使用 NSMutableURLRequest 下载网页,但将该网页放入 NSString 时遇到问题。
NSString *username = @"my_username";
NSString *password = @"my_password";
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.mypage.com/login.php?username=%@&password=%@", username, password]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnPage = [NSString stringWithFormat:@"%.*s", [returnData length], [returnData bytes]];
除了像 åäö 等特殊字符外,这工作得很好。有没有更好的方法?
I'm downloading a webpage using NSMutableURLRequest but having problem putting that very webpage into a NSString.
NSString *username = @"my_username";
NSString *password = @"my_password";
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.mypage.com/login.php?username=%@&password=%@", username, password]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnPage = [NSString stringWithFormat:@"%.*s", [returnData length], [returnData bytes]];
This works fine except for special chars like åäö etc. Is there any better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,使用以下内容:
使用 UTF8 而不是 ASCII。
Yes, use the following:
That uses UTF8 instead of ASCII.