查阅了资料发现,Cookie对象的name和value属性中不可以包含空格和一下一些字符
[ ] ( ) = , " / ? @ : ;
解决办法
URL编码:
-
(NSString )URLEncodedString
{
// CharactersToBeEscaped = @":/?&=;+!@#$()~',";
// CharactersToLeaveUnescaped = @"[].";NSString *unencodedString = self;
NSString *encodedString = (NSString )
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)unencodedString,
NULL,
(CFStringRef)@"!'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8));return encodedString;
}
URL解码: -
(NSString *)URLDecodedString
{
NSString *result = [(NSString *)self stringByReplacingOccurrencesOfString:@"+" withString:@" "];
return [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
网友评论