Re: looking for help with http post example
Re: looking for help with http post example
- Subject: Re: looking for help with http post example
- From: Jens Alfke <email@hidden>
- Date: Sun, 20 Jul 2008 15:47:34 -0700
On 20 Jul '08, at 11:53 AM, Richard Nichols wrote:
As a little additional information, I'm trying to talk to a php
script that has an API similar to Twitter.
So I need to have user password and UTF8 text.
Does the website support HTTP authentication? That's the preferred way
to interact with non-browsers. (Most websites with developer APIs,
like Twitter and del.icio.us, work this way.) NSURLConnection supports
this directly; you need to implement the callback for an
"authorization challenge" and return the username and password.
If the site _doesn't_ support HTTP auth, and thinks you're a web
browser and expects you to type the username and password into an HTML
form, and then gives you a cookie to send back ... then things are
more awkward. You have to
— Assume the site's layout isn't going to change (if the login URL or
the form fields change, your app will break)
— Construct an NSURLRequest with an HTTP method of "POST", pointing to
the login URL
— Set the request's body to the username and password and any othe
required fields, using the x-www-form-urlencoded data format
— Send the request
— Somehow figure out whether the login was accepted, probably based on
what URL you get redirected to, or what the contents of the returned
cookie are.
If you succeeded, you can just send regular requests to the site.
Cocoa will send the cookie automatically. If you ever get logged out
or the session expires, you'll have to somehow detect that based on
getting redirected back to the login page or something like that.
I'd be surprised if Windows had any components that did this stuff,
because it's a total kludge to do and very unreliable. I think you
mean components for HTTP auth, which Cocoa provides as well.
—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