iphone nsurlconnection read cookies

前端 未结 3 1733
情书的邮戳
情书的邮戳 2021-01-02 02:00

I am using async NSURLConnection to connect to a web site from iPhone. Handle didReceiveResponse is activated on response and I am trying to get all cookies, by using allHea

相关标签:
3条回答
  • 2021-01-02 02:39

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

    [request setHTTPShouldHandleCookies:YES];
    
    0 讨论(0)
  • 2021-01-02 02:40

    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)")
    }
    
    0 讨论(0)
  • 2021-01-02 02:48

    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.

    0 讨论(0)
提交回复
热议问题