【问题标题】:How to get the content of URL using AFNetworking?如何使用 AFNetworking 获取 URL 的内容?
【发布时间】:2016-01-08 18:40:06
【问题描述】:

Here 是我需要下载到我的应用程序的内容。

我是这样要求的:

GET("identifiers/pl-normal.json", parameters: nil, progress: nil, success: { sessionDataTask, response in


    }) { sessionDataTask, error in
        completionBlock(error)
}

网址请求正确:GET Optional(http://www.taboo.blue-world.pl/api/identifiers/pl-normal.json)

但是failure 块被调用,为什么?

【问题讨论】:

  • 您可以先告诉我们您遇到了什么错误。
  • The data couldn’t be read because it isn’t in the correct format. - 这是错误内容。

标签: ios json swift afnetworking


【解决方案1】:

如果无法正确解析网络请求的结果,则会在AFNetworking 中调用错误块。换句话说,这是一个序列化错误。看起来您获得的内容的 json 格式不正确。通过 json linter 运行你的服务器响应并确保它是有效的,你应该已经准备好了。

如果这不起作用,请尝试在您的序列化程序中添加 text/html 作为可接受的内容类型,如此处所述 - Request failed: unacceptable content-type: text/html using AFNetworking 2.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多