iphone nsurlconnection read cookies

陌路散爱 提交于 2019-11-30 11:59:38
Tal Bereznitskey

Try to look for it in the shared HTTP cookies storage:

for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies])
{
    NSLog(@"name: '%@'\n",   [cookie name]);
    NSLog(@"value: '%@'\n",  [cookie value]);
    NSLog(@"domain: '%@'\n", [cookie domain]);
    NSLog(@"path: '%@'\n",   [cookie path]);
}

or if working in Swift:

for cookie in HTTPCookieStorage.shared.cookies!
{
   NSLog("name: \(cookie.name)")
   NSLog("value: \(cookie.value)")
   NSLog("domain: \(cookie.name)")
   NSLog("path: \(cookie.path)")
}

Try this: in your NSMutableURLRequest, you should tell it to handle cookies:

[request setHTTPShouldHandleCookies:YES];

I don't know if it matters in apps, but what is your Accept Cookies setting for Safari in the Settings app. See if changing to Always matters.

According to some sites I've seen, a complete reboot of the iPhone is required for this setting to have any effect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!