目前还不清楚Alamofire是否支持大型数据集或渐进数据集的分组数据。对于我的应用程序来说,这是一个非常需要的特性,否则我可能不得不考虑其他方法。
在阿拉莫火吉突页面上,它声明了Progress Closure & NSProgress,但我不知道这意味着什么。
并根据维基百科对分块数据传输的描述。
Senders can begin transmitting dynamically-generated content before knowing the total size of that content.
,为了清楚起见,让我解释一下为什么我需要这个。
基本上,我有一个非常大的JSON文件,它被部分缓存。完整的JSON文件由较小的JSON对象组成。我使用iojs / nodejs通过res.write()和Express发送分块数据,后者知道不发送Content-Length报头,并将其作为块数据发送。我已经通过html/js验证了这一工作。
让我知道如果你想让我提供代码来演示这个!
发布于 2015-06-22 16:14:12
Alamofire肯定支持Transfer-Encoding: chunked数据,因为它已经被NSURLSession所支持。下面是一个从httpwatch.com下载块图像的快速示例。
let request = Alamofire.request(.GET, "http://www.httpwatch.com/httpgallery/chunked/chunkedimage.aspx")
request.progress { bytesReceived, totalBytesReceived, totalBytesExpected in
println("\(bytesReceived) - \(totalBytesReceived) - \(totalBytesExpected)")
}
request.response { request, response, _, error in
println(request)
println(response)
println(error)
}
debugPrintln(request)由于图像的内容长度不可用,因此totalBytesExpected将始终报告为-1,因为它是未知的。不过,bytesReceived和totalBytesReceived的报告是正确的。在我看来,块下载可能不是向用户展示下载进度的最佳选择,因为下载的长度还没有确定。
另一个可能有用的特性是请求上的新stream功能。它允许您在下载每个数据块时存储它。
如果这些选项不适合您的所有需求,请将您正在遇到的问题提交到我们的Github项目上,以便我们可以进一步调查。
发布于 2017-01-27 21:41:10
在Alamofire中处理分块响应的正确方法是使用stream:
let req = Alamofire.request("http://localhost:8080")
req.stream { (data) in
print(String(data: data, encoding: String.Encoding.utf8) ?? "No data")
}发布于 2015-06-12 12:41:30
以下可能会有帮助-
https://github.com/Alamofire/Alamofire#downloading-a-file-wprogress
下载文件W/进度
Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination)
.progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) in
println(totalBytesRead)
}
.response { (request, response, _, error) in
println(response)
}https://stackoverflow.com/questions/30801968
复制相似问题