Re: Send POST data to browser
Re: Send POST data to browser
- Subject: Re: Send POST data to browser
- From: glenn andreas <email@hidden>
- Date: Thu, 17 Sep 2009 12:58:18 -0500
On Sep 17, 2009, at 12:14 PM, Jens Alfke wrote:
On Sep 17, 2009, at 3:26 AM, Bartosz Białecki wrote:
I can launch browser with url using this code:
NSURL *url = [NSURL URLWithString: @"https://www.example.com/index.php
"];
[[UIApplication sharedApplication] openURL: url];
but I don't know how to send post data.
You can't do it — the browser will only do a GET on URLs it's told
to open.
I tried also another solution: send post data from my application to
website and then get a response, but then I don't know how to open
returned page in browser.
A successful POST will return one of two different things —
(1) A redirect to another page. This is a typical HTTP redirect,
with a status like 302, 303 or 307 and a Location: header that
specifies where to go. In this case you just read the URL from the
Location: header and pass that to the browser.
(2) An actual page body to display, i.e. a 200 status and a bunch of
HTML. This isn't so easy to handle, since you can't give the HTML
itself to the browser. The only way you could display it is to open
your own UIWebView (in which case it would probably be easier to
just open it before the request and use it to send the POST...)
If you own the website, then you can make sure that its login page
does (1), which is the more correct thing to do anyway.
There's no guarantee that (1) will work, since often this case also
includes setting some sort of session cookie (which goes away when the
app quits, which, of course, it does when Safari is launched). Even if
it sets a persistent cookie, I don't believe that cookies are shared
at all between your sand-boxed app and Mobile Safari.
(2) is probably the safest bet unless it's for your own website and
you can convert the CGI to support GET as well as POST.
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
Mad, Bad, and Dangerous to Know
_______________________________________________
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