Using below code I am trying to get result which should be like success or something else. But In my result value I am getting nothing, its blank.
What can be the issue?
- (IBAction)login:(id)sender {
NSString *user = [userName stringValue];
NSString *passwd = [passwordField stringValue];
NSLog(@"username:::password::: %@ %@", user, passwd);
NSURL *url = [NSURL URLWithString:@"http://myurl.html?userName=%@&userPassword=%@"];
NSError *myError = nil;
// create a plaintext string in the format username:password
NSMutableString *loginString = (NSMutableString*)[@"" stringByAppendingFormat:@"%@:%@", user, passwd];
NSString* encodedString = [[loginString dataUsingEncoding:NSUTF8StringEncoding] base64EncodedString];
// create the contents of the header
NSString *authHeader = [@"Basic " stringByAppendingFormat:@"%@", encodedString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url
cachePolicy: NSURLRequestReloadIgnoringCacheData
timeoutInterval: 3];
[request setHTTPMethod:@"POST"];
// add the header to the request. Here's the $$$!!!
// [request addValue:authHeader forHTTPHeaderField:@"Authorization"];
[request addValue:user forHTTPHeaderField:@"userName" ];
[request addValue:passwd forHTTPHeaderField:@"userPassword" ];
// perform the reqeust
NSURLResponse *response;
NSData *data = [NSURLConnection
sendSynchronousRequest: request
returningResponse: &response
error: &myError];
// *error = myError;
//the content of the webserver's response.
NSString *result = [NSString stringWithCString:[data bytes] length:[data length]];
NSLog(@"result: %@", result);
}
Any help please.
For your URL:
This is not correct.
dont you need to add here the user and password? Something like:
And.. why are you creating the strings like that? Instead of:
You should do:
I really think your problem is in the strings you are creating, check all of them