AFNetworking无法识别MAMP

Jas*_*rge 2 macos mamp ios afnetworking

我正在努力将一些NSURLConnection代码转换为AFNetworking,我看到一个奇怪的问题,它无法识别我的本地MAMP.

这是我从NSURLConnection获得的错误消息

Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo=0x160cb0 {NSErrorFailingURLStringKey=http://localhost:8888/webservices/poll.php, NSErrorFailingURLKey=http://localhost:8888/webservices/poll.php, NSLocalizedDescription=Could not connect to the server., NSUnderlyingError=0x15f910 "Could not connect to the server."}

NSURLConnection与MAMP玩得很好,我在使用AFNetworking连接到远程服务器时没有任何问题.此外,将失败的URL粘贴到我的浏览器中工作正常.

这是我正在使用的代码

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://localhost:8888/webservices/"]];
    [client getPath:@"poll.php"
         parameters:nil
            success:^(AFHTTPRequestOperation *operation, id response) {
                NSString *text = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
                NSLog(@"Response: %@", text);
            }
            failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                NSLog(@"Error");
                NSLog(@"%@", error);                                     
            }];
Run Code Online (Sandbox Code Playgroud)

我可以从远程服务器工作,但能够在本地进行更改而不必在每个编辑上传文件进行测试都会很好.我见过几个引用本地服务器的AFNetworking代码片段.任何想法可能在这里的问题?

Elf*_*red 7

尝试使用您的计算机的IP地址而不是localhost.