Используя приведенный ниже код, я пытаюсь получить результат, который должен быть как успех или что-то еще. Но в моем значении результата я ничего не получаю, оно пустое.
В чем может быть проблема?
- (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);
}
Любая помощь, пожалуйста.