停止/中止 NSURLConnection
我想知道如何在 NSURLConnection 执行加载请求时停止/中止它。
我想知道的原因是,我正在使用 NSURLConnection 解析 XML,有时获取响应所需的时间太长。
这是我的代码,让事情变得更清楚...
我正在使用 NSXMLParser 解析 XML,并在使用 NSURLConnection 请求之前使用我的肥皂消息加载请求
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn)
{
webData = [[NSMutableData data] retain];
}
}
下面的代码是标准的
-(void) connection:(NSURLConnection *) connection
didReceiveResponse:(NSURLResponse *) response
{
[webData setLength: 0];
}
-(void) connection:(NSURLConnection *) connection
didReceiveData:(NSData *) data
{
[webData appendData:data];
}
在这方面,有时需要花费时间获取连接 didReceiveData 的程序太长,用户需要中止该操作。
所以我想知道这是否可能。
我知道如何在使用 [parser abort] 开始解析后中止,但我不知道如何中止 NSURLConnection。
如果有人能帮助我解决这个问题,那就太好了。
I would like to know how I can stop/abort a NSURLConnection while it is performing it load request.
The reason I would like to know is that, I am parsing an XML using NSURLConnection and sometimes the time taken to get a response is too long.
here is my code to make things clearer...
I am parsing an XML using NSXMLParser and loading the req with my soap message before I request it using NSURLConnection
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn)
{
webData = [[NSMutableData data] retain];
}
}
The following piece of code is what is standard
-(void) connection:(NSURLConnection *) connection
didReceiveResponse:(NSURLResponse *) response
{
[webData setLength: 0];
}
-(void) connection:(NSURLConnection *) connection
didReceiveData:(NSData *) data
{
[webData appendData:data];
}
In this, sometimes the time taken for the program to get to connection didReceiveData is too long and the user would need to abort that operation.
So I would like to know if this is possible.
I know how to abort after it starts parsing by using [parser abort] but I dont know how to abort the NSURLConnection.
It would be great if someone could help me out with this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
[conn cancel];
停止正在进行的下载。Use
[conn cancel];
to stop an ongoing download.