I saw all the post on cookies …still cannot make it work…may be i m missing some concepts..Gone through apple docs and stack qns…
I want to load a url..”http://example1.com/path1″ in webview in post method where i have to post a cookie .
A cookie which pass a value with name “token” avd value “abcde1234”
firstof all set up application to accept cookies
- (void)applicationDidBecomeActive:(UIApplication *)application{
[[NSHTTPCookieStorage sharedHTTPCookieStorage]setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
}
so i created a cookie….
NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
[cookieProperties setObject:@"token" forKey:NSHTTPCookieName];
[cookieProperties setObject:@"abcde1234" forKey:NSHTTPCookieValue];
[cookieProperties setObject:@"http://example1.com" forKey:NSHTTPCookieDomain];
[cookieProperties setObject:@"http://example1.com/path1" forKey:NSHTTPCookieOriginURL];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieSecure];
Log the value with
NSHTTPCookie *cookie1;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie1 in [cookieJar cookies]) {
NSLog(@"%@", cookie1);
}
and i can see the cookie there fine…
and i am loading the url in the webview “http://example1.com/path1” as
NSURL *url = [NSURL URLWithString:@"http://example1.com/path1"];
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
[requestObj setHTTPMethod:@"Post"];
[requestObj setHTTPShouldHandleCookies:YES];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
…but the web shows exeption of missing parameter….that is the cookie that i should enter..
My question is how to set up and make all this working??that is how to setup the cookie for an url,and load in post method in webview??
I got the problem solved myself…
The post comment is being called here but miss the statement
of setting up the post request body..
Cookie was setup correctly..
Not removing the question because it can be used as ref 🙂