Reputation:
I am using below code to get connected with the HTTP server. Here how would I modify my code so that the username and password would be given through input from UITextField and the same data which will be saved in NSUserDefaults will be used next time for the connection.
NSString *urlAsString = @"http://abc.com/services/user/[email protected]&password=123456";
//urlAsString = [urlAsString stringByAppendingString:@"[email protected]"];
//urlAsString = [urlAsString stringByAppendingString:@"&pass=123456"];
NSURL *url = [NSURL URLWithString:urlAsString];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setTimeoutInterval:30.0f];
[urlRequest setHTTPMethod:@"POST"];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response,NSData *data, NSError *error) {
if ([data length] >0 && error == nil){
NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"HTML = %@", html);
receivedData = [[NSMutableData data] retain];
}
else if ([data length] == 0 && error == nil){
NSLog(@"Nothing was downloaded.");
}
else if (error != nil){
NSLog(@"Error happened = %@", error);
} }];
Upvotes: 0
Views: 344
Reputation: 12106
NSString *urlAsString = [NSString stringWithFormat:
@"http://abc.com/services/user/validateemail=%@&password=%@",
myUsernameTextField.text, // [email protected]
myPasswordTextField.text ]; // 1234565
Upvotes: 1