How to limit size of string in stringWithContentsOfURL:encoding:error:?
I do not see any answer on similar question regarding limiting size of read string from URL. A user can point by mistake on URL bringing several gigabytes 开发者_StackOverflow中文版of data which obviously will bring down my iPhone application. I want to limit size to 100Kb, is there any way to do that using the standard method?
In short, no, because the method you're referring to is pretty much a convenience method. If you want to check the size of the request prior to making it, you might as well use ASIHTTPRequest
or even just NSURLConnection
.
Specifically with ASIHTTPRequest, you'll get a delegate callback when the HTTP headers are received, so you'll know the size. Then, if the size is 100KB+, you can just cancel the request.
精彩评论