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 05-11-2011, 08:05 AM   #1 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 12
billybatigol is on a distinguished road
Default Login in this forum with Post method

I am trying to understand the way post method works on iphone sdk. But I have some problems with my html and I would like some help. As a reference I use this forum to login with post. I have wrote this code:

the .h file:

Code:
#import <UIKit/UIKit.h>
#define kFormURL @"http://www.iphonedevsdk.com/forum/login.php"

@interface RequestTypesViewController : UIViewController {

	UIWebView *webView;
	UITextField *paramName;
	UITextField *paramValue;
	NSMutableData *receivedData;

}  

@property (nonatomic, retain) IBOutlet UIWebView *webView; 
@property (nonatomic, retain) IBOutlet UITextField *paramName; 
@property (nonatomic, retain) IBOutlet UITextField *paramValue;

@property (nonatomic, retain) NSMutableData *receivedData;


- (IBAction)doPostRequest;

@end
The .m file:


Code:
#import "RequestTypesViewController.h"

@implementation RequestTypesViewController

@synthesize webView; 
@synthesize paramName; 
@synthesize paramValue;
@synthesize receivedData; 


- (IBAction)doPostRequest { 

NSURL *url = [[NSURL alloc] initWithString:kFormURL]; 
	NSMutableURLRequest *req = [[NSMutableURLRequest alloc]
								initWithURL:url]; 
	[req setHTTPMethod:@"POST"];
	
NSString *paramDataString = [NSString stringWithFormat:@"vb_login_username=%@&vb_login_password=%@", paramName.text, paramValue.text];
	
NSData *paramData = [paramDataString dataUsingEncoding:NSUTF8StringEncoding]; 
	
[req setHTTPBody: paramData];
	 
	 
	
NSURLConnection *theConnection = [[NSURLConnection alloc] 
								initWithRequest:reqdelegate:self];
	 
	 
if (theConnection) { 
	NSMutableData *data = [[NSMutableData alloc] init]; 
	self.receivedData = data; 
	[data release];
} 
else {
	[webView loadHTMLString:@"Unable to make connection!" baseURL:[NSURL 
																   URLWithString:kFormURL]] ;
}
	
	[url release]; 
	[req release]; 
	[paramName resignFirstResponder]; 
	[paramValue resignFirstResponder];
}

- (void)viewDidUnload { 
	self.webView = nil; 
	self.paramName = nil; 
	self.paramValue = nil;
}

- (void)dealloc { 
	[webView release]; 
	[paramName release]; 
	[paramValue release]; 
	[receivedData release]; 
	[super dealloc];
}

//some alerts code

@end

First of all I am not sure about the username and password names. Is this the only problem? Because I have tried everything that I found in the html source code of this forum

NSString *paramDataString = [NSString stringWithFormat:@"vb_login_username=%@&vb_login_password=%@", paramName.text, paramValue.text];

What about the rest of code? Does it seem ok?
billybatigol is offline   Reply With Quote
Old 05-11-2011, 08:37 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

no, you need a http requests sniffer to understand what you should do. (in firefox httpfox is ok)

to login in this site, you need

1- load a page where there is the form to login
2- retrieve security token parsing the html, for example (131120627-8c95a8xxxxxxxxxxxxxx7296), search the html to see it.
3- create a http request to this page
Code:
http://www.iphonedevsdk.com/forum/login.php?do=login
with the following data in POST (parameter = value) //comment
Code:
vb_login_username = username
cookieuser = 1 //or 0, this is not important, enable cookies or not
securitytoken = yourSecurityToken
do = login
vb_login_md5password = yourMd5Password
vb_login_md5password_utf = yourMd5PasswordUsingUtf
and then you are on.


I hope this is not for a bot, there are also too bot here
__________________

Last edited by dany_dev; 05-11-2011 at 08:47 AM.
dany_dev is offline   Reply With Quote
Old 05-11-2011, 08:41 AM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

firebug is another good tool
smithdale87 is offline   Reply With Quote
Old 05-11-2011, 08:46 AM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
firebug is another good tool
yes....a little heavy for just http request sniff but really powerfull.
__________________
dany_dev is offline   Reply With Quote
Old 05-11-2011, 10:49 AM   #5 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 12
billybatigol is on a distinguished road
Default

Yes. Its working. Finally!!! I have almost a week that I try to login to a site through my iphone app. Thank you very much guys. Much much appreciated.
Especially dany_dev. I will try implementing on the site that I need to login.

Can anyone tell me the basics of saving the username and password and automatically login. I don't need code. Just the process in steps.
billybatigol is offline   Reply With Quote
Old 05-11-2011, 11:05 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by billybatigol View Post
Yes. Its working. Finally!!! I have almost a week that I try to login to a site through my iphone app. Thank you very much guys. Much much appreciated.
Especially dany_dev. I will try implementing on the site that I need to login.

Can anyone tell me the basics of saving the username and password and automatically login. I don't need code. Just the process in steps.
what you mean the basics for save user\pass? NSUserDefault if you want to persist something.....

and to do http request use ASIHTTPRequest or NSURLConnection
__________________
dany_dev is offline   Reply With Quote
Old 05-11-2011, 12:51 PM   #7 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 12
billybatigol is on a distinguished road
Default

I tried in another forum and I made it work. But in the site I have to do it which is a site of a university in greece I can't make it work. It brings a error and I think it is a parameter in the login.
I must put the parameter loginTrue=login and submit1=%C5%DF%F3%EF%E4%EF%F2 but when I do this, I see the error, everything else I do returns just the login site, without actually log me in. I tried passing the submit1 as an NSString but I had the same results.
This site isn't a https site. And I see that it is a ASP.NET and application/x-www-form-urlencoded. Does this have something to do with my problem?

The link of the site is this
just in case.
billybatigol is offline   Reply With Quote
Old 05-11-2011, 01:26 PM   #8 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

in this case the link where to do the http request is
Code:
http://dionysos.teilar.gr/unistudent/login.asp
and the values
Code:
userName = yourUsername
pwd = yourPassword
submit1 = Είσοδος
loginTrue = login
__________________
dany_dev is offline   Reply With Quote
Old 05-11-2011, 05:27 PM   #9 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 12
billybatigol is on a distinguished road
Default

The problem must be in submit1 = Åßóïäïò. This word doesn't seem right. Its not a greek word. Must be a greek word with wrong text encoding. I have to find out asap. Again thank you very much!!!
billybatigol is offline   Reply With Quote
Old 05-11-2011, 06:12 PM   #10 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

try with that

Code:
submit1 = %C5%DF%F3%EF%E4%EF%F2
should work
__________________
dany_dev is offline   Reply With Quote
Old 05-11-2011, 06:42 PM   #11 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 12
billybatigol is on a distinguished road
Default

I tried it. I first wrote it as it is and later I tried pass it as a NSString.

Code:
NSString *post = [NSString stringWithFormat:@"userName=User&pwd=pass&submit1=%C5%DF%F3%EF%E4%EF%F2&loginTrue=login"];

Code:
NSString *submit = @"%C5%DF%F3%EF%E4%EF%F2";
NSString *post = [NSString stringWithFormat:@"userName=user&pwd=pass&submit1=%@&loginTrue=login", submit];
Nothing seems to work. And the submit1 = Είσοδος then you chose text encoding greek, when is a greek work meaning "enter". I also tried it with no luck. I send an email to the admin of the site. Hope dies last.
billybatigol is offline   Reply With Quote
Reply

Bookmarks

Tags
login, post

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: 355
7 members and 348 guests
doffing81, dre, iOS.Lover, Kirkout, MikaelBartlett, oztemel, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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