//同步GET
// 1 拼接网络地址
NSString *str =@"http://cdn.gq.com.tw.s3-ap-northeast-1.amazonaws.com/userfiles/images_A1/6954/2011100658141857.jpg";
// 2 将地址装为NSURL对象
NSURL *url = [NSURLURLWithString:str];
// 3 创建一个请求(request)
// 参数1 请求地址NSURL
//参数2 给请求选择一个缓存策略
// 参数3 请求超时时间
NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicytimeoutInterval:60.0];
// 4 给请求设置 请求方式
[requestsetHTTPMethod:@"GET"];
// 5 将请求发送给服务器
// 同步连接
// 参数1 请求
// 参数2 响应信息
// 参数3 错误
//同步连接的方法 会一直等待数据完整接受之后才继续执行
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnectionsendSynchronousRequest:request returningResponse:&response error:&error];
//在这里获得的是完整服务器返回的data数据
// 使用NSDdata数据
UIImage *image = [UIImageimageWithData:data];
self.imageView.image = image;
// 同步PSOST
NSString *str = @"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx";
NSURL *url = [NSURL URLWithString:str];
// 创建请求
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
// 请求方式
[request setHTTPMethod:@"POST"];
// 产生一个body
NSString *bodystr = @"date=20131129&startRecord=1&len=30&udid=1234567890&terminalType=Iphone&cid=213";
NSData *data = [bodystr dataUsingEncoding:NSUTF8StringEncoding];
// 设置post 请求 附带数据
[request setHTTPBody:data];
// 同步连接 获取数据
NSURLResponse *response = nil;
NSError *error = nil;
NSData *dataBack = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// 测试返回数据内容
NSString *result = [[NSString alloc] initWithData:dataBack encoding:NSUTF8StringEncoding];
NSLog(@"%@", result);