Do UIWebView and NSURLConnection share cookie storage?

前端 未结 1 1193
既然无缘
既然无缘 2021-02-04 00:07

I\'m building an iOS app that uses Google App Engine for the backend. Google provides an HTML login site that stores an authentication cookie. If I visit that site in a UIWebVie

相关标签:
1条回答
  • 2021-02-04 00:34

    The cookie of the UIWebView will be stored in a sandboxed cookie storage accessible through NSHTTPCookieStorage sharedHTTPCookieStorage]. You can use this cookie storage in NSURLConnection in this way:

    NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:@"__YOUR_URL__"]];
    NSDictionary *headers = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
    [request setAllHTTPHeaderFields:headers]; //A previously created NSMutableURLRequest
    

    Now you can normally use the NSURLRequest in a NSURLConnection and it will send the cookies created after the login in the UIWebView

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