Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to reuse session for CFHTTP?



Thanks Michael,

I tried calling CFHTTPMessageCopyAllHeaderFields with the HTTP request I created with CFHTTPMessageCreateRequest, but no matter when I checked that (early or late in the process), I only got an empty dictionary back. After poking around in the header files, I came across this:

CFReadStreamCreateForHTTPRequest
...
"The bytes returned are the pure body bytes; the response header has been parsed off. To retrieve the response header, ask for kCFStreamPropertyHTTPResponseHeader..."


So, I ended up calling CFStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader) and passing that result to CFHTTPMessageCopyAllHeaderFields. Now I can get at the session cookie, so life is good.

Thanks for pointing me in the right direction.

- Dave

On Feb 15, 2008, at 5:47 PM, Michael Ledford wrote:

Hello Dave,

I did find this message, http://lists.apple.com/archives/Macnetworkprog/2004/Nov/msg00048.html but I think I can give a more through answer.

Basically CFHTTP is just a way to send messages back a forth to a web server. It doesn't parse out the headers that are sent back and forth and retain them for the next call. Persistence is just for the actual socket connection to the web server itself. You would basically have to implement cookie handling by reading set-cookie headers and then sending cookies using cookie headers.

You could do this by using NSHTTPCookie and giving it a dictionary of the header fields given back by CFHTTPMessageCopyAllHeaderFields from a HTTP request. Then adding the header fields back when creating a new message obtained from requestHeaderFieldsWithCookies:.

Hope this helps!

Sincerely,
Michael Ledford

On Feb 15, 2008, at 5:14 PM, Dave Hersey wrote:

Hi,

I'm making HTTP POST requests to a server that takes/returns XML and I've been using the approached that's demonstrated in the POST Example from the /Developer/Examples/Networking folder. Basically, this approach uses CFHTTPMessageCreateRequest, CFHTTPMessageSetBody, CFReadStreamCreateForHTTPRequest and so on.

It all works great, but on the server end, a new session ID is being set up every time I send a POST request. Is there a way to extract the session cookie and reuse it with this approach or do I need to change APIs? I can't find anything of relevance in the archives or docs, but maybe the session ID is being called something else.

Thanks,

Dave


_______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden
References: 
 >How to reuse session for CFHTTP? (From: Dave Hersey <email@hidden>)
 >Re: How to reuse session for CFHTTP? (From: Michael Ledford <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.