Alamofire with localhost connection problems

纵饮孤独 提交于 2019-12-12 01:08:08

问题


I built a REST API with node.js and express and I am storing my data with mongodb.

When I send different HTTP verbs to my localhost address (http://localhost:8080/) using the Postman application, everything works perfectly.

Although, when I use Alamofire, for some reason I cannot connect to my localhost address. Here is my swift code:

func alamofireTest() {
    let url = "http://localhost:8080/"

    Alamofire.request(.GET, url)
    .responseJSON { response in
    debugPrint(response)

    if let JSON = response.result.value {
        print(JSON)
    }
}

EDIT: I am running my app from the iPhone simulator.

Any help/suggestions would be fantastic!


回答1:


For some reason it is an issue with the local host url. Works when code is deployed.



来源:https://stackoverflow.com/questions/38337206/alamofire-with-localhost-connection-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!