To understand how GET requests are made using NSURLSession in Objective-C, I would like an example. And, how is a response obtained?
NSURLSession request and response
Asked Answered
there are dozens of available answers of this question –
Blate
raywenderlich.com/110458/nsurlsession-tutorial-getting-started –
Cq
Sir,I am using objective c.Please suggest some tutorial that explains how "GET" requests are made and response is obtained from server using NSURLSession in objective c. –
Colwell
On Google, "NSURLSession GEt site:stackoverflow.com Objective-C" search gives #7673627 Did you do any research/tries on your side ? –
Marlite
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];
© 2022 - 2024 — McMap. All rights reserved.