/*------------------------get同步-------------------------------------*/
- (IBAction)GET_TB:(id)sender
{
//1.創建url
NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];
//2.創建一個請求對象
NSMutableURLRequest *requst = [NSMutableURLRequest requestWithURL:url];
//請求方式
[requst setHTTPMethod:@"get"];
NSURLResponse *response = nil;
NSError *err= nil;
//3.建立連接
NSData *data = [NSURLConnection sendSynchronousRequest:requst returningResponse:&response error:&err];
NSLog(@"%@",data);
NSLog(@"同步");
}
/*---------------------------get異步------------------------------------*/
- (IBAction)GET_YB:(id)sender
{
//1.創建url
NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];
//2.創建請求對象
NSURLRequest *requset = [NSURLRequest requestWithURL:url];
//3.建立連接
[NSURLConnection sendAsynchronousRequest:requset queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"%@",data);
}];
NSLog(@"異步");
}
/*------------------------------post同步------------------------------------------*/
- (IBAction)POST_TB:(id)sender
{
//1.創建URL
NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];
//2.創建請求對象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"post"];
//3.添加包體
NSString *str =@"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";
//將字符串轉換成NSDATA格式
NSData *dataBody = [str dataUsingEncoding:NSUTF8StringEncoding];
//4.給請求設body
[request setHTTPBody:dataBody];
//5.創建連接
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"%@",data);
NSLog(@"POST同步");
}
/*------------------------------post異步------------------------------------------*/
- (IBAction)POST_YB:(id)sender
{
//1.創建URL
NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];
//2.創建請求對象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"post"];
//3.給請求對象添加body
NSString *bodyStr = @"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";
NSData *dataBody = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:dataBody];
//4.創建連接
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"%@",data);
}];
NSLog(@"POST異步");
}
/*------------------------get同步-------------------------------------*/ - (IBAction)GET_TB:(id)sender { //1.創建url NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"]; //2.創建一個請求對象 NSMutableURLRequest *requst = [NSMutableURLRequest requestWithURL:url]; //請求方式 [requst setHTTPMethod:@"get"]; NSURLResponse *response = nil; NSError *err= nil; //3.建立連接 NSData *data = [NSURLConnection sendSynchronousRequest:requst returningResponse:&response error:&err]; NSLog(@"%@",data); NSLog(@"同步"); } /*---------------------------get異步------------------------------------*/ - (IBAction)GET_YB:(id)sender { //1.創建url NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"]; //2.創建請求對象 NSURLRequest *requset = [NSURLRequest requestWithURL:url]; //3.建立連接 [NSURLConnection sendAsynchronousRequest:requset queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { NSLog(@"%@",data); }]; NSLog(@"異步"); } /*------------------------------post同步------------------------------------------*/ - (IBAction)POST_TB:(id)sender { //1.創建URL NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"]; //2.創建請求對象 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"post"]; //3.添加包體 NSString *str =@"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215"; //將字符串轉換成NSDATA格式 NSData *dataBody = [str dataUsingEncoding:NSUTF8StringEncoding]; //4.給請求設body [request setHTTPBody:dataBody]; //5.創建連接 NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSLog(@"%@",data); NSLog(@"POST同步"); } /*------------------------------post異步------------------------------------------*/ - (IBAction)POST_YB:(id)sender { //1.創建URL NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"]; //2.創建請求對象 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"post"]; //3.給請求對象添加body NSString *bodyStr = @"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215"; NSData *dataBody = [bodyStr dataUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody:dataBody]; //4.創建連接 [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { NSLog(@"%@",data); }]; NSLog(@"POST異步"); }