I am trying to setup a http proxy server in my computer to simulate a virtual development environment.
To access the local url, I put the DNS info into computers' /etc/hosts
.
Here is my test code:
NSURLSession *session = [NSURLSession sharedSession];
NSURL *url = [NSURL URLWithString:@"http://someurl.local/bluh/bluh/path"];
NSURLSessionDataTask *dataTask =
[session dataTaskWithURL:url
completionHandler:^(NSData *data, NSURLResponse *response,
NSError *error) {
NSLog(@"data is %@ error is %@", data, error);
}];
[dataTask resume];
My Experiments:
1. Browsers like safari or chrome can access both local web services and remote web services.
2. NSURLSession will response a NSURLErrorDomain Code=-1001 "The request timed out."
when access local urls.
3. NSURLSession works correct if url not in /etc/hosts
.
I also tried the NSURLConnection
, same output as NSURLSession
's.
so, is it means the NSURLConnection
/NSURLSession
and browsers use a different strategy to do the DNS?
how to deal or bypass this?
update
I build this environment for ios 7.0+.
Environment:
- computer system:
OS X 10.9.4 (13E28)
which set up a proxy and have server in. - device system:
iOS 7.1.2(11D257)