Reputation: 37
Ive got this code to consume it works in iOS8 and iOS10 but not in iOS9
BOOL blnAnswer = NO;
NSString *strAnswer = @"";
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://10.16.2.42/api/IniciarSesionMobile/GetConnectTest"]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:35];
// Fetch the JSON response
NSData *urlData;
NSURLResponse *response;
NSError *error;
// Make synchronous request
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
// Construct a String around the Data from the response
strAnswer = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
Upvotes: 1
Views: 760
Reputation: 9589
If you want to GET the data from the server,follow the below steps
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://10.16.2.42/api/IniciarSesionMobile/GetConnectTest"]];
//If you have parameters,pass it to URL
//create the Method "GET"
[urlRequest setHTTPMethod:@"GET"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *strResponse = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"response is: %@", strResponse );
}];
[dataTask resume];
Upvotes: 1