標籤:pos res use url send project list lis new
網路解析同步非同步
/*------------------------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 [email protected]"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 [email protected]"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非同步");}
IOS 網路解析