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 > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 09-25-2009, 12:38 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 48
Question Help with HTTP Post using ASIFormDataRequest

Hello,

I'm working on a network game... and well the networking part is stalling....

I have a logon UIView with a logon UIButton that starts the following action in its ViewController:

Code:
- (IBAction) login: (id) sender
{
	// GUI Updates
	loginIndicator.hidden = FALSE;
	[loginIndicator startAnimating];	
	loginButton.enabled = FALSE;

	// Connect to server for authentication !!! WARNING !!! this is a synchronous request, blocking

	ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.mysecrutserver.com/cgi-bin/auth.pl"]] autorelease];
	
	// Setup Agent
	[request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];

	[request setPostValue:usernameField.text forKey:@"user_name"];
	[request setPostValue:passwordField.text forKey:@"password"];
	[request start];

	if ([request error])
	{
		// Error throw an alert ** Could not logon to game server **
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not logon to game server" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	else if ([request responseString])
	{
		// A valid http request, but it the server curently does not see the post vars in the web application
		NSLog (@"[DEBUG]: HTTP Response is %@",[request responseString]);
	}
}
I am connecting to the Apache web server but this code does not pass the user_name or password fields to the script running there. usernameField and passwordField are variables linked to the the text fields in the login view.

Can anyone please help me? I've Googled my fingers numb and I cannot find a solution. Most every article is asking about uploading images. Forget images I'd be happy to simply pass along a few text values!

Thanks in advance!

Encryption,
Nick Powers
encryption is offline   Reply With Quote
Old 10-01-2009, 07:30 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 53
Default ASIHttpRequest

Hi,

Try to change the user-agent string to known user-agent string. Maybe safari, firefox or explorer.

If it doesn't help go to ASIHttpRequest forum. The writer of ASIHttpRequest ( Ben ) manages the forum. He is a really nice guy, probably he will help you.
He helped me a lot with this module


Quote:
Originally Posted by encryption View Post
Hello,

I'm working on a network game... and well the networking part is stalling....

I have a logon UIView with a logon UIButton that starts the following action in its ViewController:

Code:
- (IBAction) login: (id) sender
{
	// GUI Updates
	loginIndicator.hidden = FALSE;
	[loginIndicator startAnimating];	
	loginButton.enabled = FALSE;

	// Connect to server for authentication !!! WARNING !!! this is a synchronous request, blocking

	ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.mysecrutserver.com/cgi-bin/auth.pl"]] autorelease];
	
	// Setup Agent
	[request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];

	[request setPostValue:usernameField.text forKey:@"user_name"];
	[request setPostValue:passwordField.text forKey:@"password"];
	[request start];

	if ([request error])
	{
		// Error throw an alert ** Could not logon to game server **
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not logon to game server" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	else if ([request responseString])
	{
		// A valid http request, but it the server curently does not see the post vars in the web application
		NSLog (@"[DEBUG]: HTTP Response is %@",[request responseString]);
	}
}
I am connecting to the Apache web server but this code does not pass the user_name or password fields to the script running there. usernameField and passwordField are variables linked to the the text fields in the login view.

Can anyone please help me? I've Googled my fingers numb and I cannot find a solution. Most every article is asking about uploading images. Forget images I'd be happy to simply pass along a few text values!

Thanks in advance!

Encryption,
Nick Powers
romeos28 is offline   Reply With Quote
Old 11-14-2010, 09:45 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1
Default Login with ASIFormDataRequest

Hi,

Did you manage to do it?? if so can you please let me know how you did it.
Thanks in advance.

Karthik.
*karthiksasidharan6@gmail.com



Quote:
Originally Posted by encryption View Post
Hello,

I'm working on a network game... and well the networking part is stalling....

I have a logon UIView with a logon UIButton that starts the following action in its ViewController:

Code:
- (IBAction) login: (id) sender
{
	// GUI Updates
	loginIndicator.hidden = FALSE;
	[loginIndicator startAnimating];	
	loginButton.enabled = FALSE;

	// Connect to server for authentication !!! WARNING !!! this is a synchronous request, blocking

	ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.mysecrutserver.com/cgi-bin/auth.pl"]] autorelease];
	
	// Setup Agent
	[request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];

	[request setPostValue:usernameField.text forKey:@"user_name"];
	[request setPostValue:passwordField.text forKey:@"password"];
	[request start];

	if ([request error])
	{
		// Error throw an alert ** Could not logon to game server **
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not logon to game server" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	else if ([request responseString])
	{
		// A valid http request, but it the server curently does not see the post vars in the web application
		NSLog (@"[DEBUG]: HTTP Response is %@",[request responseString]);
	}
}
I am connecting to the Apache web server but this code does not pass the user_name or password fields to the script running there. usernameField and passwordField are variables linked to the the text fields in the login view.

Can anyone please help me? I've Googled my fingers numb and I cannot find a solution. Most every article is asking about uploading images. Forget images I'd be happy to simply pass along a few text values!

Thanks in advance!

Encryption,
Nick Powers
karthiksasidharan is offline   Reply With Quote
Old 11-22-2010, 02:27 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 48
Thumbs up Thanks! Fixed with NSURLConnection and letting program idle (wait)

Quote:
Originally Posted by karthiksasidharan View Post
Hi,

Did you manage to do it?? if so can you please let me know how you did it.
Thanks in advance.

Karthik.
*karthiksasidharan6@gmail.com
Sorry I did not post back sooner, I have resolved this long ago. I abandoned ASIHttpRequest and fell back to the NSURLConnection methods.

The main problem I was having is that I wanted to wait until I determined if my login was successful or not before proceeding with my code. The solution ended up being simple (as always right?). The solution was to just wait. I disabled all forms of input and displayed a UIActivityIndicatorView and let my connectionDidFinishLoading method take control of the program flow when it was called.

Thanks for all your help!

Nick Powers
encryption is offline   Reply With Quote
Reply

Bookmarks

Tags
asiformdatarequest, asihttprequest, http, 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: 272
20 members and 252 guests
ADY, Bertrand21, Dani77, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84, Sunny46
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» 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:02 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0