NSURLConnection 和绑定的流对(CFStreamCreateBoundPair 或 CFStreamCreateBoundPairCompat)在 iPhone 3G 上不起作用
我正在使用 SimpleURLConnections 示例使用绑定的流对来实现 multipart/form-data POST 请求。它在模拟器和 iPhone 3GS/iPhone 4 上运行良好。
当我在 iPhone 3G(运行 3.1.3)上尝试时,没有数据发送到服务器。 NSURLConnection 一直挂起直到超时。经过一些测试后,我发现只有当我每个连接多次写入生产者流时才会出现问题。每当我需要多次写入时(即当我必须响应多个 NSStreamEventHasSpaceAvailable 事件时),事情就会停止工作。
这看起来像是同一个问题: NSURLRequest with HTTPBody输入流:流在打开之前发送事件,它确实提供了一种解决方法,但我还没有弄清楚我到底需要延迟什么才能解决问题。
I'm using SimpleURLConnections example to implement multipart/form-data POST request using bound pair of streams. It works great in Simulator and on iPhone 3GS/iPhone 4.
When I try it on iPhone 3G (running 3.1.3) no data gets sent to the server. NSURLConnection just keeps hanging until it times out. After some testing I figured that the problem only occurs when I write to the producer stream more than once per connection. Whenever I need to write more than once (that is when I have to respond to more than one NSStreamEventHasSpaceAvailable event) things stop working.
This looks like the same issue: NSURLRequest with HTTPBody input stream: Stream sends event before being opened, and it does provide a workaround, but I haven't figured out what exactly I need to delay in order to fix the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,似乎只有当数据适合网络堆栈的缓冲区时才会发送数据(这可以解释为什么它在模拟器上工作,其中缓冲区可能比设备上的缓冲区大得多)。
我们对此的解决方法是延迟生产者流的调度。使用performSelector:withObject:afterDelay:我们调用了一个方法,该方法在1秒后将输出流安排在运行循环上,这使得URL连接有足够的时间来打开流。
I had the same issue and it seems that the data will only be sent if it fits in the buffer of the network stack (this would explain why it works on simulator where the buffer is presumably much bigger than on the device).
The workaround we had for this was to delay scheduling of the producer stream. Using
performSelector:withObject:afterDelay:
we called a method which schedules the output stream on the run loop after 1 sec, which leaves the URL connection enough time to open the stream.