Tag: nsconnection

怎么可能connectionDidFinishLoading:运行,如果在服务器上找不到文件?

可能重复: testing使用带有HTTP响应错误状态的NSURLConnection 这是奇怪的; 我有这样的asynchronous连接: NSString *url=[NSString stringWithFormat:@"http://www.whatever.com/file"]; NSURL *url2=[NSURL URLWithString:url]; NSURLRequest *req=[[NSURLRequest alloc] initWithURL:url2]; NSURLConnection*con=[[NSURLConnection alloc] initWithRequest:req delegate:self]; [req release]; if(con){ NSMutableData *data=[[NSMutableData alloc] init]; self.receivedData=data; [data release]; } else { UIAlertView*alert=[[UIAlertView alloc] initWithTitle:@"Error!" message:@"Unable to connect to server." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } 然后我有一堆标准的委托方法: -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ [receivedData setLength:0]; } […]