iosobjective-cnsurlconnectionsendasynchronousrequest

How to call webService Using NSURLConnection in ios


Actually I am using now JSON classes for calling web-services but now i want to call that webservice using NSURLConnection any one provide me code for that.

Please provide me details of frameworks what i have to import.

Thank you in advance.


Solution

  • NSURL *url = [NSURL URLWithString:stringurl];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    
    [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
     {
         NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
         NSLog(@"%@",dictionary);
     }];
    

    You Can use this.