NSURLRequest 接收数据太晚
我正在使用 NSURLRequest 从 Java Servlet 接收数据。 Servlet 立即向输出流写入内容。
NSURLRequest 立即接收响应 connection:didReceiveResponse:
,但接收数据持续 15 - 20 秒。 (这就是 didReceiveResponse
和 didReceiveData
之间的时间)。看起来 NSURLRequest 正在缓冲数据并等待更多数据。
我该如何预防这个问题?
I'm using a NSURLRequest to receive data from an Java Servlet.
The Servlet is writing something to the outputstream immediately.
NSURLRequest immediately receives the response connection:didReceiveResponse:
, but receiving the data lasts 15 - 20 seconds. (So that's the time between didReceiveResponse
and didReceiveData
). It looks like NSURLRequest is buffering the data and waits for more data.
How can I prevent the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSURLConnection 使用低级缓冲来收集字节。
didReceiveResponse 和 didRecieveData 之间存在差异 - 因为存在一些可能导致延迟的代理/数据路由。
为了执行您的指标,您应该记录第一次 didRecieveData 和 connectionDidFinishLoading 之间的时间,并比较您在网络浏览器上执行相同操作的时间。
希望这有帮助。
NSURLConnection use low level buffering to collect the bytes.
There is a difference between didReceiveResponse and didRecieveData - as there would be some proxying/data routing that might cause the delay.
In order to perform your metrics you should be recording the time between first didRecieveData and connectionDidFinishLoading and compare the time when you do same on your web-browser.
Hope this helps.