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);
}];
リモートサーバーから作業することもできますが、テストするために編集するたびにファイルをアップロードしなくても、ローカルで変更を加えることができれば便利です。ローカルサーバーを参照するAFNetworkingコードのスニペットをいくつか見てきました。ここで問題になる可能性のあるアイデアはありますか?