Sending Cookies in NSMutableURLRequest
Sending Cookies in NSMutableURLRequest
- Subject: Sending Cookies in NSMutableURLRequest
- From: Jerry Krinock <email@hidden>
- Date: Mon, 12 Sep 2011 15:12:10 -0700
When I send message -setHTTPShouldHandleCookies:YES to an NSMutableURLRequest, does that mean that it will search in -[[NSHTTPCookieStorage sharedHTTPCookieStorage], find all the cookies that are qualified by domain and path, and send them when in an NSURLConnection created with this request?
If so, I'm not getting expected results. Is there a way to see the cookies that are actually being sent? Cookies don't seem to show in -allHTTPHeaders, and I cannot see them in tcpdump either if using SSL (https).
If not, what is the correct way to add cookies to a request? I've tried the following code, to generate the value of a "Cookie: " string in the Netscape format:
// cookies is a dictionary of cookies I want to send in request
NSMutableString* cookieString = nil ;
for (NSString* cookieName in cookies) {
NSString* value = [[cookies objectForKey:cookieName] value] ;
if (!cookieString) {
cookieString = [NSMutableString string] ;
}
else {
[cookieString appendString:@";"] ;
}
[cookieString appendFormat:@"%@=%@", cookieName, value] ;
}
// At this point, cookieString is, for example:
// "name1=value1;name2=value2"
[mutableRequest setValue:cookieString
forHTTPHeaderField:@"Cookie"] ;
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden