Keep losing php session cookie in UIWebView

后端 未结 1 1632
说谎
说谎 2020-12-17 05:36

I\'m new to the forum and also quite new to iOS Dev. I\'m having trouble with a UIWebView, where I keep losing login permission to a HTML form which sets a phpsession cookie

相关标签:
1条回答
  • 2020-12-17 05:49

    I use in my app many requests and every time when I send a request I get the cookies for the url from NSHTTPCookieStorage. I do not use NSUserDefaults or something else to store the cookies.

    When I send a new request I set the needed cookies my self

    NSURL *myURL = ....
    NSMutableRequest *mutableRequest = ....
    NSArray *cookiesToSet = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:myURL];
    for (NSHTTPCookie *cookie in cookiesToSet) {
        [cookieStringToSet appendFormat:@"%@=%@;", cookie.name, cookie.value];
    }
    
    if (cookieStringToSet.length) {
        [mutableRequest setValue:cookieStringToSet forHTTPHeaderField:@"Cookie"];
    }
    

    And it works

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