利用AFHTTPRequestOperation请求服务端时请求URL中带有中文字符可以通过如下方法正确请求。
NSString * requestStr = [[NSStringalloc]initWithFormat:@"http://api.jiepang.com/recommend/venuelists?city=北京&count=1&apiver=20121015"];
NSString *strURL = [requestStrstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//加上次句可解决请求出现Bad URL问题
NSURL *url = [NSURLURLWithString:strURL];
NSURLRequest *request = [NSURLRequestrequestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperationalloc] initWithRequest:request];
[operationsetCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,id responseObject) {
NSLog(@"Success: %@", operation.responseString);
}failure:^(AFHTTPRequestOperation *operation,NSError *error) {
NSLog(@"Failure: %@", error);
}];
[operationstart];