- (void)getRegions
{
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[request setHTTPMethod:@"GET"];
[request setValue:@"value" forHTTPHeaderField:@"请求头"];
//NSData *received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection)
{
self.datas = [NSMutableData new];
}
// NSError *error;
// NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:received options:kNilOptions error:&error];
// return jsonDic;
}
#pragma mark- NSURLConnection 回调方法
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{// ①
[_datas appendData:data];
}
-(void) connection:(NSURLConnection *)connection didFailWithError: (NSError *)error
{
NSLog(@"%@",[error localizedDescription]);
}
- (void) connectionDidFinishLoading: (NSURLConnection*) connection
{// ②
NSLog(@"请求完成…");
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:_datas options:NSJSONReadingAllowFragments error:nil];
//[self reloadView:dict];
NSLog(@"%@", dict);
}