views:

196

answers:

3

Hello

I am using async NSURLConnection to connect to a web site from iPhone. Handle didReceiveResponse is activated on response and I am trying to get all cookies, by using allHeaderFields from NSHTTPURLResponse

I see many hreader, but no Set-Cookie - it looks like iphone simulator just ignores them... And I am sure cookies are present in response - network monitor shows they present

I do not use any http storage - all that I am trying to do is to print to log all header - and do not see cookies info

Does anybody know about this issue?

UPDATE I have made some research: if my website returns custom header, like "Custom-Header: value" - then this header is visible in java client, but is not in iphone...

thanks

A: 

I don't know if it matters in apps, but what is your Accept Cookies setting for Safari in the Settings app. See if changing to Always matters.

According to some sites I've seen, a complete reboot of the iPhone is required for this setting to have any effect.

Lou Franco
I am using simulator and do not use automatic cookies storage. All that I want is to see raw http headers - and I see all of them, but Cookie
A: 

Try this: in your NSMutableURLRequest, you should tell it to handle cookies:

[request setHTTPShouldHandleCookies:YES];
Don
I have this line, still no cookies (both YES/NO). The strange thing is that I see all headers, but cookies...and I want just to see them, and handle myslef
Where are you setting this? I think it should be before you set any other values on the request. Also, cf. http://www.cocoadev.com/index.pl?ParsingHTTPHeaders
Don
yes, I call it right after request initialization.Anyway: the question is not only about cookies - I would like to see ALL headers and system does not do it (see my update in initial post)
A: 

Try to look for it in the shared HTTP cookies storage:

for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies])
{
    NSLog(@"name: '%@'\n",   [cookie name]);
    NSLog(@"value: '%@'\n",  [cookie value]);
    NSLog(@"domain: '%@'\n", [cookie domain]);
    NSLog(@"path: '%@'\n",   [cookie path]);
}
Tal Bereznitskey