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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 09-02-2010, 05:05 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 4
Default how can i login a webwite with username and password through ASIHTTPRequest?

Quote:
<form method="post" id="loginForm" class="login-form" action="http://www.renren.com/PLogin.do" >

<p class="top clearfix">
<label for="email">username:</label><input type="text" name="email" class="input-text" id="email" tabindex="1" value=""/>
</p>
<p class="clearfix">
<label for="password">password:</label>
<input type="password" id="password" name="password" error="please input a password" class="input-text" tabindex="2" />
</p>
<div class="caps-lock-tips" id="capsLockMessage" style="display:none"></div>
<p class="savepassword">
<label title="!" for="autoLogin" class="labelCheckbox">
<input type="checkbox" name="autoLogin" id="autoLogin" value="true" tabindex="3" />
</label>
</p>
<p class="bottom"> <input type="hidden" name="origURL" value="http://www.renren.com/Home.do" />

<input type="hidden" name="domain" value="renren.com" />
<input type="submit" id="login" class="input-submit" value="login" tabindex="4" />
<span class="getpassword"><a href="http://safe.renren.com/findPass.do" stats="home_findpassword">not remember the password?</a></span>
</p>
</form>

i'm a noob.
i would to use ASIFormDataRequest.
thanks awksome man.


i use the fiddler get some information.

Quote:
POST http://www.renren.com/PLogin.do HTTP/1.1
Host: www.renren.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://www.renren.com/
Cookie: _r01_=1; mop_uniq_ckid=10.7.16.26_1283219788_478435532; XNESSESSIONID=d74cca71f29d; jebecookies=d11ec7e1-6857-4c24-883b-2386fa5e1a88|||||; depovince=ZJ
Content-Type: application/x-www-form-urlencoded
Content-Length: 119

email=myusername&password=mypassword&origURL=http% 3A%2F%2Fwww.renren.com%2FHome.do&domain=renren.com

Last edited by xlbu; 09-02-2010 at 05:11 AM.
xlbu is offline   Reply With Quote
Old 09-02-2010, 08:48 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 4
Default

It will be something like this:

Code:
        NSURL* url = [NSURL URLWithString:@"http://www.renren.com/PLogin.do"];
	ASIHTTPRequest* request = [ASIFormDataRequest requestWithURL: url];
	[request setPostValue: @"user account email" forKey:@"email"];
	[request setPostValue: @"user account password" forKey:@"password"];
	[request setPostValue: @"http://www.renren.com/Home.do" forKey:@"origURL"];
	[request setPostValue: @"renren.com" forKey:@"domain"];

	[request setDelegate: self];
	[request startAsynchronous];
then in your delegate class(in my code I set it up to self) you have to implement some methods from ASIHTTPRequestDelegate protocol:
Code:
- (void)requestStarted:(ASIHTTPRequest *)request;
- (void)requestReceivedResponseHeaders:(ASIHTTPRequest *)request;
- (void)requestFinished:(ASIHTTPRequest *)request;
- (void)requestFailed:(ASIHTTPRequest *)request;

- (void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data;

- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request;
- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request;
DaTa is offline   Reply With Quote
Old 09-02-2010, 10:40 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 4
Default

Quote:
Originally Posted by DaTa View Post
It will be something like this:

Code:
        NSURL* url = [NSURL URLWithString:@"http://www.renren.com/PLogin.do"];
	ASIHTTPRequest* request = [ASIFormDataRequest requestWithURL: url];
	[request setPostValue: @"user account email" forKey:@"email"];
	[request setPostValue: @"user account password" forKey:@"password"];
	[request setPostValue: @"http://www.renren.com/Home.do" forKey:@"origURL"];
	[request setPostValue: @"renren.com" forKey:@"domain"];

	[request setDelegate: self];
	[request startAsynchronous];
then in your delegate class(in my code I set it up to self) you have to implement some methods from ASIHTTPRequestDelegate protocol:
Code:
- (void)requestStarted:(ASIHTTPRequest *)request;
- (void)requestReceivedResponseHeaders:(ASIHTTPRequest *)request;
- (void)requestFinished:(ASIHTTPRequest *)request;
- (void)requestFailed:(ASIHTTPRequest *)request;

- (void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data;

- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request;
- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request;
thanks for your help.i will try it..if some problems appear ,maybe will i trouble you.
xlbu is offline   Reply With Quote
Old 10-09-2010, 12:21 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Australia
Posts: 180
Default

I have same question on this too, but i couldnt get it to submit the form

Code:
<form name="form2" method="post" action="/webtix/welcome/welcome.do">

<input type="text" name="cardNum" id="serial" size="25" maxlength="24"/></td>
<input name="pass" type="password" id="passwd" size="25" maxlength="24"/></td>
<input class="go_btn" type="submit" value="Login" id="gobtn2" onclick="return validate(this.form);" />

</form>
Code:
NSURL* url = [NSURL URLWithString:@".../webtix/welcome/welcome.do"];
ASIFormDataRequest* request = [ASIFormDataRequest requestWithURL: url];
[request setPostValue:@"01234" forKey:@"cardNum"];
[request setPostValue:@"01234" forKey:@"pass"];
[request setDelegate: self];
[request startAsynchronous];
I still cant get data from login page...can anyone tell me what is wrong with my code?
svveet is offline   Reply With Quote
Reply

Bookmarks

Tags
asihttprequest post login

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
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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