Error Domain=NSURLErrorDomain Code=-1003 "找不到指定主机名的服务器 [英] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found

查看:161
本文介绍了Error Domain=NSURLErrorDomain Code=-1003 "找不到指定主机名的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在设备上运行应用程序时出现此错误.当我在模拟器上运行它时,我没有收到此错误,并且发布请求工作正常.这是我的代码片段:

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];

感谢任何帮助.谢谢

推荐答案

使用 Xcode 11.2.1,在 macOS 项目上工作时,我遇到了同样的问题.

With Xcode 11.2.1, working on a macOS project, I had the same issue.

这里的修复是:

  • 在项目资源管理器中点击项目
  • 选择签名&能力标签
  • 选中 AppSandbox 部分中的网络:传出连接(客户端)"复选框

这篇关于Error Domain=NSURLErrorDomain Code=-1003 "找不到指定主机名的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆