Domain Error = NSURLErrorDomain Code = -1003 "Server with the specified host name was not found

I get this error when I try to run the application on the device. I do not get this error when I run it on the simulator and the mail request is working fine. This is the code snippet that 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

+6
source share
2 answers

This error usually indicates a DNS related problem. Check the DNS settings on your device and confirm that you can browse the Internet using Safari or another browser (double check by visiting a site that you have not visited before to make sure 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.

+11
source

The simulator uses a network connection to your computers, so I recommend checking System Preferences> Network> Advanced> Proxies> Automatically setting up a proxy server: you must disable Auto conf.

+4
source

Source: https://habr.com/ru/post/979010/


All Articles