iOS 错误代码=-1003“找不到具有指定主机名的服务器。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42996709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS Error Code=-1003 "A server with the specified hostname could not be found."
提问by Async-
I am trying to load image from URL on the iphone, image is there and I can open it in safari with same link, but not in the app:
我正在尝试从 iPhone 上的 URL 加载图像,图像在那里,我可以使用相同的链接在 safari 中打开它,但不能在应用程序中打开它:
Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname
could not be found." UserInfo={NSUnderlyingError=0x17024f810
{Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)"
UserInfo={_kCFStreamErrorCodeKey=50331647, _kCFStreamErrorDomainKey=6147928288}},
NSErrorFailingURLStringKey=https://........, NSErrorFailingURLKey=https://.........
Code of request:
请求代码:
func downloadImage(userEmail: String, onCompletion: @escaping (UIImage) -> Void) {
print("Download Started")
let route = "\(baseURL as String)\(userEmail as String)\(baseURLparameters as String)"
let url = URL(string: route)
getDataFromUrl(url: url!) { (data, response, error) in
guard let data = data, error == nil else {
print("===failed:", error ?? "dunno")
print("===url:", url?.absoluteString ?? "dunno")
return
}
print(response?.suggestedFilename ?? url!.lastPathComponent )
print("Download Finished")
DispatchQueue.main.async() { () -> Void in
onCompletion(UIImage(data: data)!)
}
}
}
回答by Udaya Sri
回答by de.
回答by JeremyP
The host name in your URL is wrong because the message you are getting back explicitly states it can't find a server with that host name.
您的 URL 中的主机名是错误的,因为您返回的消息明确指出它找不到具有该主机名的服务器。
The mst likely cause is that you have forgotten to put a forward slash between the base URL and the email e.g. if your base URL is
最可能的原因是您忘记在基本 URL 和电子邮件之间添加正斜杠,例如,如果您的基本 URL 是
http://example.com
and your email is
你的电子邮件是
[email protected]
You construct
你构造
http://[email protected]
Put a break point on the line that creates the URL and inspect the string it is trying to create it from. It'll probably then be pretty obvious exactly what you are doing wrong.
在创建 URL 的行上放置一个断点并检查它试图从中创建它的字符串。然后很可能很明显你做错了什么。
回答by Sreejith s
This error would suggest as DNS related issue.There is some problem with DNS server reached through our WiFi network. So we change DNS server and fix this problem. Remove cache and try again.
此错误提示为 DNS 相关问题。通过我们的 WiFi 网络访问的 DNS 服务器存在一些问题。所以我们更换了 DNS 服务器并解决了这个问题。删除缓存并重试。
If there is a url you can GET (instead POST) on the same server.
如果有一个 url,你可以在同一台服务器上 GET(而不是 POST)。
And Also, turning off wifi and using 3G makes the error go away.
而且,关闭 wifi 并使用 3G 会使错误消失。
回答by bshirley
This happened in my case because one of the paths in our development servers were internal to our firewall/intranet/VPN and my device was not on our internal wi-fi.
在我的情况下发生了这种情况,因为我们开发服务器中的路径之一在我们的防火墙/内联网/VPN 内部,而我的设备不在我们的内部 Wi-Fi 上。
Frustrating and confusing because it was working in the simulator and not on a device.
令人沮丧和困惑,因为它在模拟器中而不是在设备上工作。