Alamofire与本地主机连接问题 [英] Alamofire with localhost connection problems

查看:119
本文介绍了Alamofire与本地主机连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用node.js构建了REST API并进行了表达,并使用mongodb存储了数据。

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

当我向本地地址发送不同的HTTP动词时( http:// localhost:8080 / ),使用Postman应用程序,一切正常。

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

虽然,当我使用Alamofire时,由于某种原因,我无法连接到我的本地主机地址。这是我的快速代码:

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)
    }
}

编辑:我正在从iPhone模拟器运行我的应用程序。

I am running my app from the iPhone simulator.

任何帮助/建议都非常棒!

Any help/suggestions would be fantastic!

推荐答案

由于某种原因,这是本地主机URL的问题。部署代码后有效。

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

这篇关于Alamofire与本地主机连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆