[英]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
. 在尝试使用
Alamofire
和Swift 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.