Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSURLSession请求和响应_Ios_Objective C_Iphone_Mobile Application - Fatal编程技术网

Ios NSURLSession请求和响应

Ios NSURLSession请求和响应,ios,objective-c,iphone,mobile-application,Ios,Objective C,Iphone,Mobile Application,为了了解如何在Objective-C中使用NSURLSession发出GET请求,我想举个例子。那么,如何获得响应呢?GET NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"give your url here"]]; //create the Method "GET" [urlRequest setHTTPMethod:@"GET"]; NS

为了了解如何在Objective-C中使用NSURLSession发出GET请求,我想举个例子。那么,如何获得响应呢?

GET

NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"give your url here"]];

//create the Method "GET" 
[urlRequest setHTTPMethod:@"GET"];

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
  NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
  if(httpResponse.statusCode == 200)
  {
    NSError *parseError = nil;
    NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
    NSLog(@"The response is - %@",responseDictionary);
  }
  else
  {
    NSLog(@"Error");     
  }
}];
[dataTask resume];

这个问题有几十个答案,先生,我使用的是objective c。请提供一些教程,解释如何在objective c中使用NSURLSession从服务器获取“获取”请求和响应。在谷歌上,“NSURLSession获取站点:stackoverflow.com objective-c”搜索提供了您是否做过任何研究/尝试?