Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HARDWARRIOR

macrumors member
Original poster
Nov 17, 2008
52
0
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%"> </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?
 

jjgraz

macrumors regular
Feb 13, 2009
103
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.