Ios NSURLSession请求和响应
为了了解如何在Objective-C中使用NSURLSession发出GET请求,我想举个例子。那么,如何获得响应呢?GETIos 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
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”搜索提供了您是否做过任何研究/尝试?