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!
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
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!
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
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! Fixed with NSURLConnection and letting program idle (wait)
Quote:
Originally Posted by karthiksasidharan
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.