Re: Log Into a Website
Re: Log Into a Website
- Subject: Re: Log Into a Website
- From: Jens Alfke <email@hidden>
- Date: Tue, 15 Jul 2008 23:06:47 -0700
On 15 Jul '08, at 10:09 PM, Bridger Maxwell wrote:
I am writing a Cocoa app that will access a user's account that is
set up on
a server. How do I log in and keep logged in? Do I keep a connection
open?
It depends on the protocol you're using. I think you mean HTTP, in
which case the answer is "no" — HTTP is stateless, so it doesn't
matter (except for performance) whether you leave a connection open
between requests.
Website logins are done using cookies, usually. If you're using
NSURLConnection, it will track cookies automatically, though you might
have to use the NSHTTPCookieStorage class if you want to customize the
behavior (I've never had to, though.) It's up to the server to decide
how long the cookie lasts before expiring.
On the other hand, if you're writing a web service to be used
programmatically (like the APIs that a lot of sites such as flickr
support) then logins are usually done with HTTP Authentication, which
sends the credentials in the header of each request. NSURLConnection
supports that too. There's no notion of a "session" in this case:
every request is independent of the others. That's a key part of the
HTTP architecture (look up "REST architectural style" on Wikipedia if
you're curious.)
Also, from the server side (php, ruby, etc.) can I use sessions to
keep
track of a user being logged in from a Cocoa application, or does
that only
work when using a browser?
Cookies will work the same way programmatically.
Perhaps there is an example or an open source
program I can pick apart? This will have to be a secure connection
too.
There's open-source Cocoa code that accesses various popular websites'
APIs. For example, Cocoalicious talks to del.icio.us.
SSL connections are no problem. Just make sure the URL you connect to
uses the "https" scheme.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden