I have a server working locally (my IP address is 192.168.0.98) and experimented with some network code to access it. This was originally done through AFNetworking, but I did it using NSURLSession as follows:
NSURLSession *session = [NSURLSession sharedSession]; NSURL *url = [NSURL URLWithString:@"http://192.168.0.98:8080/api"]; NSURLSessionDataTask *task = [session dataTaskWithURL: url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSLog(@"Error: %@", error); NSLog(@"Body: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); }]; [task resume];
Then I run it with these three URLs:
Where 192.168.0.98 is the IP assigned to this machine. If I run these URLs from PAW or browser, it works fine. But from unit test, it fails.
From my project perspective, I can just use localhost . So this is not an interruption of the transaction. But I'm curious why it doesn't work.
Does anyone know what the problem is?
source share