您應該使用實現NSConnectionDataDelegate
協議,並使用NSConnection
類。我相信在調用-(void) connectionDidFinishLoading:(NSURLConnection *)connection
時,頁面已完成加載。
-(void) requestPage
{
NSString *urlString = @"http://the.page.you.want.com";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0f];
responseData = [[NSMutableData alloc] init];
connection = [[NSURLConnection connectionWithRequest:request delegate:self] retain];
delegate = target;
}
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
if ([response isKindOfClass:[NSHTTPURLResponse class]])
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
//If you need the response, you can use it here
}
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
}
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[responseData release];
[connection release];
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
if (connection == adCheckConnection)
{
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//You've got all the data now
//Do something with your response string
[responseString release];
}
[responseData release];
[connection release];
}
這是不行的 – NouNou
這將無法正常工作?你能多給我一點嗎? –
thans James.try在我的文章中查看源代碼並查看腳本後的所有
是源,只需使用視圖生成的源代碼在Firefox與Web開發人員擴展或擴展Firebug
來源
2011-10-27 13:53:49 user466764
感謝,但我想下載生成的源和分析它們 – NouNou
相關問題