NSURLRequest中不支持的URL

gho*_*der 31 json objective-c nsurlrequest ios

如果我从终端运行此请求,我可以正常看到JSON请求:

curl -XGET 192.168.0.6:8888/scripts/data/backend2/index.php/name/_all
Run Code Online (Sandbox Code Playgroud)

我的NSURlRequest代码是这样的:

 NSURLRequest *request = [NSURLRequest requestWithURL:
                             [NSURL URLWithString:@"192.168.0.6:8888/scripts/data/backend2/index.php/name/_all"]];

    [[NSURLConnection alloc] initWithRequest:request delegate:self];
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

didFailWithError
2013-11-29 22:31:08.164 Ski Greece[607:a0b] Connection failed: Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo=0xcd042d0 {NSErrorFailingURLStringKey=192.168.0.6:8888/scripts/data/backend2/index.php/name/_all, NSErrorFailingURLKey=192.168.0.6:8888/scripts/data/backend2/index.php/name/_all, NSLocalizedDescription=unsupported URL, NSUnderlyingError=0xdbdcc70 "unsupported URL"}
Run Code Online (Sandbox Code Playgroud)

如何调用该URL?我无法访问服务器代码 - 我知道只是设置回报我需要的东西,如果我调用该URL?

Viz*_*llx 50

尝试在您的网址中加入适当的网址方案,例如

[NSURL URLWithString:@"http://www...

  • 我有一个以http://开头的URL ...我仍然收到错误.谁知道还有什么可能导致这个? (9认同)

小智 22

在我的情况下,我修复它:

strURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Run Code Online (Sandbox Code Playgroud)

strURL包含带URL的字符串.


小智 10

在我的情况下,我访问在我自己的mac上运行的服务,所以我的网址是127.0.0.1:8080/list

添加http://方案后.有用!

现在它是http://127.0.0.1:8080/list而不是127.0.0.1:8080/list


kes*_*hav 9

我也为同样的错误而努力,即使url路径是正确的但是在http之前有一个空格,如下所示:

NSString *path = @" http://www.mylink/";
NSURL *url = [NSURL URLWithString:path];
Run Code Online (Sandbox Code Playgroud)

所以我把url作为nil,所以它给了"不支持的URL".然后删除为我工作的空间.