Iphone NSHTTPCookie的问题
我想做一个登录应用程序。我的第一个屏幕登录表单包含两个文本字段和一个按钮。按下此按钮时,我会调用一个调用此方法的方法:Iphone NSHTTPCookie的问题,iphone,objective-c,ios4,nshttpcookie,Iphone,Objective C,Ios4,Nshttpcookie,我想做一个登录应用程序。我的第一个屏幕登录表单包含两个文本字段和一个按钮。按下此按钮时,我会调用一个调用此方法的方法: - (int)login { // Add data to post request NSHTTPURLResponse * response; NSString *myRequestString = [[NSString alloc] initWithFormat:@"userdata='%@'&passdata='%@'",
- (int)login {
// Add data to post request
NSHTTPURLResponse * response;
NSString *myRequestString = [[NSString alloc] initWithFormat:@"userdata='%@'&passdata='%@'",
username.text, password.text];
NSError * error;
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request;
request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://server.com/login.php"]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60] autorelease];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: myRequestData];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@"http://server.com/login.php"]];
//int cid;
for (NSHTTPCookie *cookie in all) {
NSLog(@"Name: %@ : Value: %@", cookie.name, cookie.value);
// cid = (int)cookie.value;
}
// NSLog(@"id: %d",cid);
[myRequestString release];
[request release];
return 1;
}
当我按下此按钮时,我的程序崩溃,并在此行旁边:
NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@"http://sms.britecs.com/login.php"]];
我有Thread1:程序收到信号:“EXC\u BAD\u ACCESS”
,但不知道如何修复它
我还有一个问题。如何在下一屏幕中使用此cookies
感谢
[请求发布]代码>您正在释放自动释放的对象。不要这样做,它将在下一个运行循环周期由自动释放池释放。在初始化结束时删除autorelease,您就没事了,否则删除release语句
您正在创建它:
request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://server.com/login.php"]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60] autorelease]; // <---
request=[[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@]http://server.com/login.php"]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60]自动释放];//当您为活动可执行文件启用NSZombieEnabled时,控制台会说什么?请看一下。谢谢@Nick Weaver:)[request release];导致错误,但不知道为什么。是的,我现在看到了。非常感谢:)