Ziel c Cookies an uiwebview senden

Ich muss Cookies senden, um mich bei einem UIWebView anzumelden, aber beim Laden der Webseite wurden die Cookies nicht gesendet.

Mein Code ist:

CorreoViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title =AMLocalizedString(@"Correo", @"");
    NSURL *url=[NSURL URLWithString:@"https://cuentas.uv.es/cgi-bin/p/user/Usuario"];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];

    NSArray * cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
    NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies: cookies];

    [request setHTTPMethod:@"Post"];
    [request setHTTPShouldHandleCookies:YES];
    [request setAllHTTPHeaderFields:headers];

    NSLog(@"Request: %@", [[request allHTTPHeaderFields] objectForKey:@"cookie"]);

    [self.webView loadRequest:request];
    // Do any additional setup after loading the view.
}

Und die Cookies, die ich in meinem Cookie-Speicher habe, sind:

COOKIE 0: NSHTTPCookie Version: 0 Name: "PAPIAuthNcook" Wert: "nBNqHJSdjgo1aBw0uGh3AXzElIHCxA% 2FDbnipSHWZbU5Eh1cJfUr18GEP9zxB% 2Bl% 2FZGPBAKQu6oF2l% 0AzIMt7ywiSECLBuOHJnvS7y6rVim2HfE% 3D% 0A" expiresDate: (null) erstellt: 2014.01.16 15.05.41 0.000 (4,11578 e + 08) sessionOnly: TRUE domain: "cuentas.uv.es" path: "/" isSecure: FALSE

COOKIE 1: NSHTTPCookie-Version: 0 Name: "PAPIslist" Wert: "17201128679244079 |https://uvapp.uv.es/"expiresDate: (null) erstellt: 2014-01-16 15:05:41 +0000 (4.11578e + 08) sessionOnly: TRUE domain:" cuentas.uv.es "path:" / "isSecure: FALSE

COOKIE 2: NSHTTPCookie Version: 0 Name: "PAPIAuthNcook" Wert: "nBNqHJSdjgo1aBw0uGh3AXzElIHCxA% 2FDbnipSHWZbU5Eh1cJfUr18GEP9zxB% 2Bl% 2FZGPBAKQu6oF2l% 0AzIMt7ywiSECLBuOHJnvS7y6rVim2HfE% 3D% 0A" expiresDate: (null) erstellt: 2014.01.16 15.05.41 0.000 (4,11578 e + 08) sessionOnly: TRUE domain: "as.uv.es" path: "/" isSecure: FALSE

COOKIE 3: NSHTTPCookie-Version: 0 Name: "PAPIslist" Wert: "17201128679244079 |https://uvapp.uv.es/"expiresDate: (null) erstellt: 2014-01-16 15:05:41 +0000 (4.11578e + 08) sessionOnly: TRUE domain:" as.uv.es "path:" / "isSecure: FALSE

AppDelegate.m

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    [[NSHTTPCookieStorage sharedHTTPCookieStorage]setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
}

Danke im Voraus.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage