• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
WKWebView and cookies
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

WKWebView and cookies


  • Subject: WKWebView and cookies
  • From: Torsten Curdt <email@hidden>
  • Date: Tue, 12 Apr 2016 11:27:40 +0200

I am starting a request in a WKWebView on the iOS 9.3 simulator

    let url = NSURL(string:"http://localhost:8000/";)
    let req = NSMutableURLRequest(URL:url!)
    webView.loadRequest(req)

and intercept the response where I try to print out the cookies

    func webView(webView: WKWebView, decidePolicyForNavigationResponse
navigationResponse: WKNavigationResponse, decisionHandler:
(WKNavigationResponsePolicy) -> Void) {
        if let httpResponse = navigationResponse.response as?
NSHTTPURLResponse {
            if let headers = httpResponse.allHeaderFields as? [String:
String], url = httpResponse.URL {
                NSLog("cookies for %@", url)
                let cookies =
NSHTTPCookie.cookiesWithResponseHeaderFields(headers, forURL: url)
                for cookie in cookies {
                    NSLog(cookie.description)
                    NSLog("found cookie " + cookie.name + " " +
cookie.value)
                }
                NSLog("cookies for %@ done", url)
            }
        }
        decisionHandler(WKNavigationResponsePolicy.Allow)
    }

The first request is to show a form - no cookies

    GET /
    cookies for http://localhost:8000/
    cookies for http://localhost:8000/ done

The POST then triggers the backend to set one

    POST /
    Set-Cookie: remember=1; Max-Age=300; Path=/; Expires=Tue, 12 Apr 2016
08:56:41 GMT
    cookies for http://localhost:8000/
    cookies for http://localhost:8000/ done

but I still cannot see the cookie on the client.

If I now restart the app the cookie is sent

    GET /
    Cookie: remember=1

and the backend confirms that the cookie is set - but I still can't see it
from the WKWebView.

    cookies for http://localhost:8000/
    cookies for http://localhost:8000/ done

I also tried to find it in the cookie storage

    NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies!

but that does not seem to have it either.

After lots of reading of StackOverflow and searching the mailing list
archives I am left a bit puzzled.
What am I missing here?

cheers,
Torsten
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: WKWebView and cookies
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Tab bar and split view controllers together?
  • Next by Date: Re: WKWebView and cookies
  • Previous by thread: Tab bar and split view controllers together?
  • Next by thread: Re: WKWebView and cookies
  • Index(es):
    • Date
    • Thread