Managing HTTP Cookies on iPhone
code:
-(IBAction)getCookieMethod
{
NSLog(@"Hi dinesh.");
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)theConnection didReceiveResponse:(NSURLResponse *)response
{
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSDictionary *fields = [HTTPResponse allHeaderFields];
NSLog(@"fields are : %@\n", fields);
NSString *cookie = [fields valueForKey:@"Set-Cookie"]; // It is your cookie
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]];
[request addValue:cookie forHTTPHeaderField:@"Cookie"];
}
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data
{
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; //check the data accessibility for return data
NSLog(@"data String %@", dataString);
}
- (void)connection:(NSURLConnection *)theConnection didFailWithError:(NSError *)error
{
NSLog(@"Connection fail Error .");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)theConnection
{
NSLog(@"connectionDidFinishLoading");
}
regards,
dinesh
No comments:
Post a Comment