开发者

ASIHTTPRequest: limiting download size

I'm building an app where you do a search, and I want to preview the docum开发者_运维百科ent, showing the paragraph around the first search term. The documents might be 20 or 30K in size, but because it could be returning 100 results, I'd like to minimize the amount of data coming in over a 3G connection.

I'm currently doing this to fetch the document:

    __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlAddress]];
    __block NSString *responseString;
    [request setCompletionBlock:^{
        responseString = [[request responseString] copy];

        _preview = responseString;
    }];

    [request startSynchronous];

This all works fine, but grabs the entire document. What I'd like to do is only grab up to the place where the search keyword is. Is there a way to a) see what data is coming in as it's coming it, so that I can check to see if there's a match; and b) once I have a match, cancel the download, and just deal with what's come in so far?


Try to set didReceiveDataSelector. This selector will be called when request recives data. So you can store all recived data and check its size each time request receives new portion of data. Also you can search you keyword in all that data.
But this will prevent ASIHTTPRequest from populating responseData or writing the data to downloadDestinationPath. So you must store the response yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜