ASIHTTPRequest and Cyrillic letters

混江龙づ霸主 提交于 2019-12-12 01:41:38

问题


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

I had this request:

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

After this I have requestFinished: and requestFailed: methods:

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

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?

Thanks in advance!


回答1:


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


来源:https://stackoverflow.com/questions/12106135/asihttprequest-and-cyrillic-letters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!