与iphone中的NSURLConnection进行HTTP连接 [英] HTTP connection with NSURLConnection in iphone

查看:113
本文介绍了与iphone中的NSURLConnection进行HTTP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常感谢您的回复。我被困在这里。你能帮忙解决这个问题吗? CFHTTPStream可以解决这个问题吗?还有其他方法可以解决这个问题吗?谢谢。

Thanks a lot for reply. I am stuck here. Can you please help with this situation? Can CFHTTPStream will resolve this problem? Is there any other way to work with this problem ? Thanks.

您好,

我使用NSURLConnection连接到HTTP网址。
我应该在一段时间间隔后得到响应(响应没有从服务器关闭)。
是否可以读取那些响应的人,就像在java中的http url连接的输入流上有无限的while循环一样。
未调用didReceiveData方法。

I am connecting to an HTTP url using NSURLConnection. I am supposed to get response after some time intervals (The response is not getting closed from server). Is it possible to read those responsed whenever they are written just like having an infinite while loop on input stream of http url connection in java. The didReceiveData method is not getting called.

将其视为http推送,其中响应将根据其在服务器上的可用性进行写入。

Consider it as an http push where response will be written according to its availability on server.

我应该可以连接到服务器&保持联系直到我没有关闭连接。

I should be able to connect to server & remain connected till I don't close the connection.

感谢您的帮助。

推荐答案

我也用这个撞到墙上,但我找到了解决办法:

I was banging my head against the wall with this as well, but I found a solution:

NSURLConnection 似乎确实缓冲了数据,但你可以通过在响应头中设置内容类型来欺骗它。例如,通过将内容类型设置为text / json,我可以在响应中仅从服务器发送几个字节,而不关闭流,并获取 didReceiveData 回调方法给我数据。

NSURLConnection does seem to buffer up data, but you can trick it by setting the content type in the response header. By setting the content type to "text/json" for example, I could send only a few bytes from the server in the response, without closing the stream, and get the didReceiveData callback method to give me the data.

在此之前,我不得不用4k左右填写我的回复要回击的回调。

Before that, I had to pad my responses with 4k or so for the callback to hit.

这篇关于与iphone中的NSURLConnection进行HTTP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆