NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray *_tmpArray = [NSArray arrayWithArray:[cookieJar cookies]];
NSLog(@"obj == %@",[_tmpArray objectAtIndex:0]);
for (int i = 0; i < [_tmpArray count]; i++)
{
NSHTTPCookie *cookie = [_tmpArray objectAtIndex:i];
NSLog(@"%@",[cookie value]);
[USER_DEFAULT setObject:[cookie value] forKey:@"SID"];
[USER_DEFAULT synchronize];
}
self.req = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:urlStr]];
NSMutableDictionary *tempDictHead = [[NSMutableDictionaryalloc]initWithCapacity:10];
[tempDictHead setObject:@"XMLHttpRequest"forKey:@"X-Requested-With"];
self.req.requestHeaders = tempDictHead;
self.req.delegate = self;
[self.req setDidFinishSelector:@selector(success:)];
[self.req setDidFailSelector:@selector(loginFailed:)];
[self.reqstartAsynchronous];
+(void)creatRequest:(NSString *)urlString paramDict:(NSMutableDictionary *)paramDict delegate:(id)delegate{
// NSLog(@"paramDict====%@",paramDict);
ASIFormDataRequest *requestForm = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
if (! [delegate isKindOfClass:[UIView class]]) {
BaseViewController *baseVc = (BaseViewController*)delegate;
baseVc.formDataRequest = requestForm;
}
for (id key in [paramDict keyEnumerator])
{
// NSLog(@"===++===%@",[paramDict objectForKey:key]);
[requestForm setPostValue:[paramDict objectForKey:key] forKey:key];
}
// requestForm.HEADRequest = @"X-Requested-With:XMLHttpRequest";
[requestForm setDelegate:delegate];
[requestForm startAsynchronous];
如果是后面一种应该在 ASIFormDataRequest.m里面的 - (void)buildURLEncodedPostBody 方法里面加入:
[selfaddRequestHeader:@"X-Requested-With"value:@"XMLHttpRequest"];