[英]Unable to connect from IPv6 to IPv4 Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found
[英]Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found
尝试在设备上运行应用程序时收到此错误。 当我在模拟器上运行它时,我没有收到此错误,并且发帖请求工作正常。 这是我的代码片段:
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];
任何帮助表示赞赏。 谢谢
此错误通常表明存在DNS相关问题。 检查设备上的DNS设置,并确认您可以使用Safari或其他浏览器浏览Internet(通过访问您之前未访问过的网站进行仔细检查,以确保未缓存该网站)。
如果有一个网址,您可以在同一服务器上获取(而不是POST),请尝试直接在设备上的Safari中访问它。
模拟器使用您的计算机网络连接,因此我建议检查系统偏好设置>网络>高级>代理>自动代理配置:您必须禁用自动配置。
使用Xcode 11.2.1进行macOS项目时,我遇到了同样的问题。
解决方法是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.