Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 2, 2009, 04:36 AM   #1
HARDWARRIOR
macrumors member
 
Join Date: Nov 2008
How to POST url in safari?

Hi!
I want my app to open url in Safari and to login.
I know how to just open URL:
Code:
	UIApplication *app = [UIApplication sharedApplication];
	[app openURL:[[NSURL alloc] initWithString:@"http://www.somedomain.net"]];
But there is a login form on that site. Here is it's code:
Code:
<form action="http://www.somedomain.net/login.php" method="post">
...
                  <td width="68%"><input name="username" class="formlogin" size="23" type="text" /></td>
                  <td width="10%">&nbsp;</td>
                </tr>
                <tr>
                  <td>Password:</td>
                  <td><input name="pass" class="formlogin" size="23" type="password" /></td>
it looks like I have to POST params to http://www.somedomain.net/login.php
Well, I know how to POST
Code:
	NSString *myRequestString = @"username=sampleuser&pass=samplepass";
	NSData *myRequestData = [NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
	NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://somedomain.net/login.php" ]]; 
	[ request setHTTPMethod: @"POST" ];
	[ request setHTTPBody: myRequestData ];
	NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
	[connection release]; 
	[request release];
But how to combine it all together? Just POSTing and calling openURL does not work. Is it possible at all? openURL opens safari and GETs? What if a site could log me in on GET request with username and pass as params, would openURL work then?
HARDWARRIOR is offline   0 Reply With Quote
Old Mar 7, 2009, 08:39 PM   #2
jjgraz
macrumors regular
 
Join Date: Feb 2009
Not sure if I'm on target with this answer. But I thought it was worth mentioning that many applications log into websites through means of a web Service. For instance. You write the code as you have done, and send it to a PHP file or SOAP file which then logs the user in, and can transfer data to databases ect. Just a thought.
jjgraz is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Major Safari annoyance: before finishing typing URL, Safari loads random page PBF OS X Mavericks (10.9) 8 Oct 2, 2013 02:17 AM
Splitting the search/URL bar in Safari 6? mcdj Mac Applications and Mac App Store 42 Jun 21, 2013 01:41 PM
URL Shortener for Safari IGregory Mac Applications and Mac App Store 6 Mar 11, 2013 10:04 AM
iOS Safari URL bar delays JBsea Web Design and Development 1 Dec 17, 2012 09:43 PM
Safari 6 unified search / url bar declandio Mac OS X 10.7 Lion 1 Jul 29, 2012 09:33 AM

Forum Jump

All times are GMT -5. The time now is 01:55 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC