如何在iOS中使用NSURLConnection调用webService

har*_*yas 4 objective-c nsurlconnection ios sendasynchronousrequest

实际上,我现在使用JSON类来调用Web服务,但是现在我想使用NSURLConnection任何为我提供代码的Web服务来调用该Web服务。

请向我提供我必须导入的框架的详细信息。

先感谢您。

小智 6

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);
 }];
Run Code Online (Sandbox Code Playgroud)

您可以使用它。