ASIHTTPRequest和西里尔字母 [英] ASIHTTPRequest and Cyrillic letters

查看:108
本文介绍了ASIHTTPRequest和西里尔字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天, 我正在使用ASIHTTPRequest,并且在请求中遇到西里尔字母的问题.

Good day, I'm working with ASIHTTPRequest, and I'm facing a problem with cyrillic letters in the request.

我有这个要求:

self.getUsersFromSearchRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@&text=%@&count=20", SEARCH_FOR_USER, searchBar.text]]];
[self.getUsersFromSearchRequest setDelegate:self];
[self.getUsersFromSearchRequest startAsynchronous];

此后,我有 requestFinished: requestFailed:方法:

    - (void)requestFinished:(ASIHTTPRequest *)request {
    self.dictionary = [NSJSONSerialization JSONObjectWithData:[request responseData] options:NSJSONWritingPrettyPrinted error:nil];

    if([request isEqual:self.getUsersFromSearchRequest]) {
        if ([[self.dictionary objectForKey:@"response"]  isKindOfClass:[NSArray class]]) {

            self.resultSearchUser = [self.dictionary objectForKey:@"response"];
            [self.searchDisplayController.searchResultsTableView reloadData];
        }
        self.searchResultsTable.hidden = NO;
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }
}

- (void)requestFailed:(ASIHTTPRequest *)request {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Internet Connection Error Alert Title", @"This is the Internet Connection Error Alert Title") message:NSLocalizedString(@"Internet Connection Error Alert Message Text", @"This is the Internet Connection Error Alert Message Text") delegate:nil cancelButtonTitle:NSLocalizedString(@"Internet Connection Error Alert Cancel Button Title", @"This is the Internet Connection Error Alert Cancel Button Title") otherButtonTitles:nil];
    [alertView show];
}

当我在搜索文本字段中输入拉丁字母时,一切都很好,但是在输入西里尔字母后,我立即输入了 requestFailed:.怎么了?

When I enter latin letters into the search text field, everything is going fine, but after I entered cyrillic letters I'm immediately entering requestFailed:. What is wrong?

提前谢谢!

推荐答案

问题已解决! 您必须对URL字符串进行编码! 像这样:

Problem Solved! You must encode the URL string! Like this:

self.getUsersFromSearchRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[[NSString stringWithFormat:@"%@&text=%@&count=20", SEARCH_FOR_USER, searchBar.text] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

这篇关于ASIHTTPRequest和西里尔字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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