2016-05-08 5 views
0

私は、これは私のコードAlamofireでローカルホストのAPIからJSONを取得するにはどうすればよいですか?スウィフト

Alamofire.request(.GET, "localhost/speex/service.php") 
     .responseJSON { response in 
      debugPrint(response) 
    } 

ですが、それは、このエラー

[Request]: <NSMutableURLRequest: 0x7fc53960dda0> { URL: localhost/speex/service.php } 
[Response]: nil 
[Data]: 0 bytes 
[Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSUnderlyingError=0x7fc539567ad0 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}, NSErrorFailingURLStringKey=localhost/speex/service.php, NSErrorFailingURLKey=localhost/speex/service.php, NSLocalizedDescription=unsupported URL} 
[Timeline]: Timeline: { "Request Start Time": 484405610.886649, "Initial Response Time": 484405612.654189, "Request Completed Time": 484405612.654189, "Serialization Completed Time": 484405612.654278, "Latency": 1.76753997802734 secs, "Request Duration": 1.76753997802734 secs, "Serialization Duration": 8.89897346496582e-05 secs, "Total Duration": 1.76762896776199 secs } 

PD私を送信し、ローカルホストからJSONを取得したい:私はURLを開く「はlocalhost/Speexに/ service.php "JSONコードが正しく表示されます

答えて

2

iOSシミュレータまたはデバイス内でLocalhostにアクセスできません。ローカルホストのローカルIPアドレスをhttp://192.168.1.100のように設定し、プログラムでこのIPアドレスを使用する必要があります。

関連する問題