Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found
Solution 1
With Xcode 11.2.1, working on a macOS project, I had the same issue.
The fix here was:
- Click on project in project explorer
- Select the Signing & Capabilities tab
- Check "Network: Outgoing connections (client)" checkbox in the AppSandbox section
Solution 2
This error would typically suggest a DNS related issue. Check the DNS settings on your device and confirm you can browse the internet using Safari or another browser (double check by visiting a site you have not visited before to ensure it is not cached).
If there is a url you can GET (instead of POST) on the same server, try visiting it directly in Safari on the device.
Solution 3
The simulator uses your computers network connection, so I recommend checking the System Preferences > Network > Advanced > Proxies > Automatic Proxy Configuration : You must disable Automatic conf.
Admin
Updated on November 22, 2020Comments
-
Admin over 3 years
I get this error when I try running the app on a device. I do not get this error when I run it on the simulator and the post request works fine. This is code snippet I have:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:300.f]; [request setHTTPMethod:@"POST"]; NSData* data = [paramString dataUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody:data]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [connection start];
Any help is appreciated. Thanks
-
Chris Allinson almost 9 yearsSweet ... I had a similar issue and it turned out that my endpoint was not reachable on my wifi network (i.e. physical device) but was on my hardwired laptop (i.e. iOS Simulator). I had to use a different secure in-house wifi network.
-
Mujib Saiyyed over 8 yearsThanks man. You are awesome. I had same problem and i was checking safari for internet connectivity. Every time it showed Google page and i felt i had working internet connection. After reading your answer, I checked opening another pages and found that Goggle page was cached one. +1
-
ios developer almost 8 yearsi just can't understand that in Android it will work fine with the network but in ios not. what can i exactly do for solve this issue?
-
Dania Delbani over 7 yearsHey is problem solved for you? I have a similar issue I tried a GET request in Safari and its work fine but within my app I get the same error
-
JoCa over 3 yearsWhere do I find this in XCode 11.6 ?
-
AmitaiB over 3 years@JoCa It's only for macOS projects, I believe, so you won't see it in iOS projects. Threw me for a minute as well.