gpt4 book ai didi

iphone - NSHTTPCookie 的问题

转载 作者:行者123 更新时间:2023-12-03 21:07:13 25 4
gpt4 key购买 nike

我想制作登录申请。我的第一个屏幕登录表单有两个文本字段和一个按钮。当我按下此按钮时,我会调用一个方法来调用此方法:

- (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_BAD_ACCESS”但不知道如何修复它。

我还有一个问题。我如何在下一个屏幕中使用此 cookie?

谢谢

最佳答案

使用[request release];,您将释放一个自动释放的对象。不要这样做,它将由自动释放池在下一个运行循环周期释放。在初始化结束时删除自动释放就可以了,否则删除释放语句。

在这里您正在创建它:

request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://server.com/login.php"]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60] autorelease]; // <---

关于iphone - NSHTTPCookie 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5960211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com