- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想制作登录申请。我的第一个屏幕登录表单有两个文本字段和一个按钮。当我按下此按钮时,我会调用一个方法来调用此方法:
- (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/
我刚刚更新到 Xcode7 并试图将我的项目切换为使用 Swift 2.0 语法,但在我使用的开源库中的文件中遇到此错误。这是相关代码: public lazy var cookies:[String
我想制作登录申请。我的第一个屏幕登录表单有两个文本字段和一个按钮。当我按下此按钮时,我会调用一个方法来调用此方法: - (int)login { // Add data to post request
在我的 iPhone 应用程序中,我希望能够在应用程序重新启动时重用相同的服务器端 session 。服务器上的 session 由 cookie 标识,该 cookie 在每次请求时发送。当我重新启
我正在使用 ASIFormDataRequest 并获取 cookie 作为响应。我试图将它们保存到 NSUserDefaults 中,如下所示: NSArray * requestCookies =
这是我的代码 let cookieProperties = [ NSHTTPCookieOriginURL: Constants.baseUrl, NSHTTP
我有一个包含以下内容的 NSHTTPCookie 对象: apns_token:(null)> 我可以使用单个元素 [cookie valueForKey:@"domain"] 如何遍历所有键? 最
我正在使用 NSHTTPCookie 创建一个 cookie。但是当我创建时,到期日期被转换为创建日期。这是我的代码: NSMutableDictionary *cProperties = [NSMu
我的应用程序需要一个注销按钮,我有以下代码: while ([[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] count
我正在尝试在 Swift 中编写几个 cookie,以便在我显示 webview 时,它能够读取这些 cookie 并做出适当的 react 。我找到了许多关于如何创建 cookie 和阅读 Appl
使用一些代码删除所有 cookie 后: NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage s
我有一个 UIWebView显示登录页面。用户填写用户名和密码,登录后页面保存NSHTTPCookie在应用程序沙箱中。 有了这行代码[[NSHTTPCookieStorage sharedHTTPC
我使用 Alamofire 从服务器获得响应 cookie。我的代码如下: let urlPath :String = LOGIN_URL Alamofire.request(.POS
我正在使用以下代码来构造 NSHTTPCookie 但是没有选项可以为 cookie 设置 httpOnly 标志 [cookieProperties setObject:@"name" forKey
我使用下面的代码来创建一个cookie,但是失败了。(iOS SDK 5) // add cookie NSDictionary *properties = [NSDictionary diction
我有一个以 HTTP cookie 形式从 Web 服务收到的身份验证 token 。目前,我依赖于 iOS 的默认行为,即在 NSHTTPCookieStorage 对象中存储从 HTTP 请求返回
我有一个 MonoTouch iPhone 应用程序,它通过 Azure 访问控制服务进行联合登录。登录是通过嵌入式 UIWebView 浏览器完成的。登录完成后,我想将 cookie 传输到我的应用
我是一名优秀的程序员,十分优秀!