我正在啓動一個請求,該請求將內部重定向返回給HTML。爲什麼didReceiveData函數沒有被第二次調用?我正在嘗試下載一個JSON文件。 (使用iOS6)NSURLConnection連接:didReceiveData:在重定向後不被調用
- (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;
}
http://stackoverflow.com/questions/1446509/handling-redirects-correctly-with-nsurlconnection –