Sportica   Sportica

ios Url Encode

//ios Url Encode 
//有时候在请求的参数里里特殊符号比如“+”等。而如果没有encode的话那么传过去的还是”  ”,面实际上是%2B。
-(NSString*)UrlValueEncode:(NSString*)str
{
        NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                               (CFStringRef)str,
                                                                               NULL,
                                                                                  CFSTR("!*'();:@&=+$,/?%#[]"),
                                                                               kCFStringEncodingUTF8);
       [result autorelease];
       return result;
}



//- (NSString*)URLDecodedString:(NSString*)str
//{
////    NSString *result = [[self stringByReplacingOccurrencesOfString:@"%0D%0A" withString:@""] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    NSString *result = [[str stringByReplacingOccurrencesOfString:@"%0D%0A" withString:@""] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    return [result stringByReplacingOccurrencesOfString:@"+" withString:@" "];
//}

 

posted @ 2013-10-28 11:26  qingjoin  阅读(3045)  评论(0编辑  收藏  举报
  Sportica