Answer the question
In order to leave comments, you need to log in
How to parse json server response in objective-c?
Good day to all!
I'm making an iOS client for the site and there was a problem.
I send a request to the server with an e-mail and a password.
//нажимаем на кнопку sign up
- (IBAction)enterButton:(id)sender {
NSString *myEmail = textFieldEmail.text;
NSString *myPassword= textFieldPassword.text;
//url encoding email
NSString *encodeEmail = myEmail;
NSString *escapedStringEmail = [encodeEmail stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
//md5 password
NSString *md5Paswword = [NSString md5String:myPassword];
NSString *url = [NSString stringWithFormat:@"http://site.com/app/api/user/auth/%@/%@", escapedStringEmail, md5Paswword];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL
URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0];
request.HTTPMethod = @"POST";
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection) {
receviedData = [[NSMutableData data] init];
}
NSLog(@"%@", request);
}
//возвращаем ответ авторизаци
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receviedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receviedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *data = [[NSString alloc] initWithData:receviedData encoding:NSUTF8StringEncoding];
UIAlertView *authResult = [[UIAlertView alloc] initWithTitle:@"Результат" message:data delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[authResult show];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question