Hi I am trying to connect to some server which will use username and password as credentials..Following is the code I am using.
NSString post =[[NSString alloc] initWithFormat:@”userName=*&password=*“];
NSURL url=[NSURL URLWithString:@”******“];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSLog(@"request:%@",request);
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Here the problem is server is giving user invalid message.But the credentials which i am giving is fine.This username and password is not going in request object..can any one of you please help me..
You need to start with a string that holds your username & password. This will form the http POST body. You need to replace username_input_field & password_input_field with the correct input field names for the webserver. My advice is to use Firefox along with the httpFox extension to login to your webserver. httpFox will show you all the input field names for the request. There may also be extra hidden fields which you’ll need to add too.