在ViewDidLoad方法中,我添加了以下代码
self.responseData = [NSMutableData data];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"my url"]];
[request setHTTPShouldHandleCookies:YES];
[request setHTTPMethod:@"GET"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
And When connection start delegate methods are calling
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSUInteger responseStatusCode = [httpResponse statusCode];
_responseData = [[NSMutableData alloc] init];
NSLog(@"connection");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// Append the new data to the instance variable you declared
[_responseData appendData:data];
NSLog(@"_responseData%@",_responseData);
}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
willCacheResponse:(NSCachedURLResponse*)cachedResponse {
// Return nil to indicate not necessary to store a cached response for this connection
return nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError *jError;
jArray= [NSJSONSerialization JSONObjectWithData:_responseData options:NSJSONReadingMutableContainers error:&jError];
[_tableView reloadData];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"didFailWithError");
}
这是我点击HTTPS网址的方式,但显示数据需要更多时间。没有得到什么问题。任何人都可以帮我解决这个问题。