Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-09-2010, 05:12 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default POST Data To Form

I was wondering how I would post a username and password into this form:

Code:
<form action="/login.php" method="post" name="login">
	<input type="hidden" name="req" value="" />
	<fieldset id="login">
	<legend><img src="/images/key.gif" /> Login to your account</legend>
	<br />
	<div>
	Enter your email address          </div>
	<div>
	<input name="username" type="text" maxlength="64" value="" id="input" autocomplete="off">
	</div>
	<div>
	Password          </div>
	<div>
	<input name="password" type="password" maxlength="40" value="" id="input" autocomplete="off">
	</div>
	<div>
	<input name="loginsubmit" type="submit" value="Login now" id="button">
	</div>
	</fieldset>
	</form>
It has the fields of Username and Password, but how would I manipulate this so my application could fill this in and eventually display the contents in a UIWebView?

I attempted to use ASIHTTPRequest and got nowhere with it. Thanks in advance for any help :/
Speed is offline   Reply With Quote
Old 08-09-2010, 08:54 PM   #2 (permalink)
Code before baby wakes up
 
RobotWoods's Avatar
 
Join Date: Sep 2009
Posts: 189
RobotWoods is on a distinguished road
Default

Have two UITextFields (usr and pwd in the below example) and a button to fire the following:

Code:
NSURL *url = [NSURL URLWithString: @"http://yourserver/login.php"];	 
NSString *body = [NSString stringWithFormat: @"username=%@&password=%@",usr.text, pwd.text];
NSMutableURLRequest *mainRequest = [[NSMutableURLRequest alloc]initWithURL: url];
[mainRequest setHTTPMethod: @"POST"];
[mainRequest setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
NSData *returnData = [ NSURLConnection sendSynchronousRequest: mainRequest returningResponse: nil error: nil];
then turn returnData into whatever form you need to proceed
RobotWoods is offline   Reply With Quote
Old 08-09-2010, 10:51 PM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

Thanks so much! NSLog is showing a bunch of HTML and mixed code, how would I be able to combine this into the login.php script and execute the result in a UIWebView? I am attempting to work on it via the mployd.com/login.php page.
Speed is offline   Reply With Quote
Old 08-09-2010, 11:04 PM   #4 (permalink)
Code before baby wakes up
 
RobotWoods's Avatar
 
Join Date: Sep 2009
Posts: 189
RobotWoods is on a distinguished road
Default

I think you have to use the loadHTMLString method but I haven't done that myself, so don't have any advice.

If it were your script, you could have it output a success/error code and display accordingly.
RobotWoods is offline   Reply With Quote
Old 08-10-2010, 09:32 AM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

Would there be a way to login like this? For example, if I send the login details like that using POST, could I then display the webpage normally and have the user logged in?
Speed is offline   Reply With Quote
Old 08-10-2010, 09:53 AM   #6 (permalink)
Code before baby wakes up
 
RobotWoods's Avatar
 
Join Date: Sep 2009
Posts: 189
RobotWoods is on a distinguished road
Default

Does this work for you (swapped last line):

Code:
NSURL *url = [NSURL URLWithString: @"http://yourserver/login.php"];	 
NSString *body = [NSString stringWithFormat: @"username=%@&password=%@",usr.text, pwd.text];
NSMutableURLRequest *mainRequest = [[NSMutableURLRequest alloc]initWithURL: url];
[mainRequest setHTTPMethod: @"POST"];
[mainRequest setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
[yourUIWebView loadRequest: mainRequest];
It should work in some cases, but I don't know if it can handle things like cookies
RobotWoods is offline   Reply With Quote
Old 08-10-2010, 05:14 PM   #7 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

I had previously tried adding the web-view with the request and it had still shown me logged out. Luckily, I was able to implement a search function using URL manipulation. Do you know any ways that I could pull data from a webpage? For example, pull some data from this webpage (Job Search for cook - Looking for cook Jobs - cook Jobs) and display the headers such as COOK and CAMP COOK. For example, add the links to an array and then save the paths of the links so someone could just tap on it and it would take them to that page in a webview. I am about to conduct an intensive series of google searches on this but I just thought I should ask ahead.

EDIT: Hypothetically, this is the code that displays the data. The bolded parts are what I would like to pull:

Code:
<div id="search_title"><a href="/job.php?id=12008" target="_top">CAMP COOK</a></div>
						<div id="search_company"><a href="/company/2011" title="Pinnacle Profile and Jobs">Pinnacle</a> - 
						Winnipeg, Manitoba, 						
						<a href="/country.php?id=CA">Canada</a>						</div>
<div id="search_desc">Cravings restaurant is looking for both a prep cook as well as a line cook. Available during the week, evenings and weekends. We are located in Stonewall, Manitoba a 15-20 min drive, North of Winnipeg. Experience is required as we are a new restauran...</div>
Hypothetically, I would arrange it inside of a table view. I would have a title, then a description, then the url when the user taps. I was thinking something like this:

Code:
webdisplay *searchResults = [[webdisplay alloc] initWithNibName:@"webdisplay" bundle:nil];
	[self.navigationController pushViewController:searchResults animated:YES];
	[searchResults release];
//This would be to swap the views when tapping in the table view, then in the next view's viewDidLoad:

-(void)viewDidLoad {

pulledURL = [NSString stringWithFormat:@"/job.php?id=1200"]; //I would import the bolded URL piece from above
regularURL = [NSString stringWithFormat:@"http://mployd.com"];

NSString *websiteLink = [NSString stringWithFormat:@"%@%@"],regularURL,pulledURL];

[website loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:websiteLink]]];
	website.scalesPageToFit = YES;
	[website release];

}

Last edited by Speed; 08-10-2010 at 05:36 PM.
Speed is offline   Reply With Quote
Old 08-10-2010, 10:38 PM   #8 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

I managed to be able to get the html code from the web-page after loading. How would I manage to isolate some of that code?
Speed is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 322
8 members and 314 guests
ilmman, iram91419, linkmx, nadav@webtview.com, Objective Zero, Paul Slocum, stanny, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,656
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, iram91419
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:40 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0