我想做登录应用程序。我的第一个屏幕登录表单有两个文本字段和一个按钮。当我按下此按钮时,我会调用一个调用此方法的方法:
- (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: Program received signal: "EXC_BAD_ACCESS"
但不知道如何解决它。
我还有一个问题。如何在下一个屏幕中使用此 cookie?
谢谢