我正在启动一个请求,它给我返回带有重定向的 HTML。为什么没有第二次调用 didReceiveData 函数?我正在尝试下载 JSON 文件。(使用iOS6)
- (void) testdownload{
NSURL *url = [NSURL URLWithString:@"https://***];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d{
NSString *tmpdata = [[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
NSLog(@"data: %@", tmpdata);
}
当我使用 UIWebView 时,将处理重定向并显示 JSON 文件。使用此功能不起作用:
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse{
return request;
}