NSURLConnection and keep-alive

↘锁芯ラ 提交于 2019-12-06 01:58:22

问题


I have a small bug in my client app that uses NSURLConnection. I have tracked it down to an unexpected connection keep-alive that seems to confuse the web server (probably a bug on the server side). The workaround would be to force-close all outstanding connections at a certain point. Can I do this somehow with NSURLConnection, i.e. something like

[NSURLConnection closeAllIdleConnections];


回答1:


ASIHTTPRequest has an expirePersistentConnections method. It may do what you're looking for.

It's not a drop-in replacement for NSURLConnection, but it's not too hard to port code from NSURLConnection to ASIHTTPRequest.




回答2:


I think you might want to look at the following method defined for NSURLConnections. This assumes that you made the call asynchronously. If it isn't an async call, then it probably should be.

cancel Cancels an asynchronous load of a request.

  • (void)cancel

Discussion Once this method is called, the receiver’s delegate will no longer receive any messages for this NSURLConnection.

Hope this helps. Andrew.



来源:https://stackoverflow.com/questions/3596515/nsurlconnection-and-keep-alive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!