简体   繁体   English

Alamofire请求错误-SWIFT 2.0

[英]Request error with Alamofire - SWIFT 2.0

How to solve this error? 如何解决这个错误?

Request failed with error: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." 请求失败,出现错误:错误域= NSURLErrorDomain代码= -1005“网络连接丢失。” UserInfo={NSUnderlyingError=0x7fc77b041ce0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey= https://www.themoviedb.org/search/remote/multi ?, NSErrorFailingURLKey= https://www.themoviedb.org/search/remote/multi ?, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSLocalizedDescription=The network connection was lost.} UserInfo = {NSUnderlyingError = 0x7fc77b041ce0 {Error Domain = kCFErrorDomainCFNetwork Code = -1005“(null)” UserInfo = {_ kCFStreamErrorCodeKey = -4,_kCFStreamErrorDomainKey = 4}},NSErrorFailingURLStringKey = https://www.themoviedb.org/search/remote/ multi ?,NSErrorFailingURLKey = https://www.themoviedb.org/search/remote/multi?,_ kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -4,NSLocalizedDescription =网络连接丢失。}

I was getting the same error after trying to add parameters to a .GET request using Alamofire and Swift 2 . 在尝试使用AlamofireSwift 2.GET请求中添加参数后,出现了相同的错误。 I have found several links where the question has been asked, but have not seen any actual answers. 我找到了几个已提出问题的链接,但没有看到任何实际答案。 Suggestions for other versions of this error with different kCFStreamErrorDomainKeys don't work. 对于具有不同kCFStreamErrorDomainKeys的此错误的其他版本的建议不起作用。 This seems to be a bug with the latest version of Alamofire , but as a workaround I was able to get my code working by manually adding the parameters to the url string. 这似乎是最新版本的Alamofire一个错误,但是作为一种变通办法,我能够通过手动将参数添加到url字符串来使代码正常工作。

ie - instead of specifying a url of " https://mywebservice.com/api/mycontroller " and adding parameters:["name":"bob"] you could use 即-您可以使用以下url代替指定“ https://mywebservice.com/api/mycontroller ”的url并添加参数:[“ name”:“ bob”]

https://mywebservice.com/api/mycontroller?name=bob https://mywebservice.com/api/mycontroller?name=bob

Of course this gets more difficult if you are passing many parameters. 当然,如果要传递许多参数,这将变得更加困难。

You can generate a string like that at runtime: " https://mywebservice.com/api/mycontroller?name= " + name 您可以在运行时生成类似这样的字符串:“ https://mywebservice.com/api/mycontroller?name= ” +名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM