post请求:
- (void)postRequest {
NSString *urlString = [NSString stringWithFormat:@"http://f1.netgears.cn:8081/cloudadmin_new/interface/commonQueryDataObject.action"];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *str = @"opercode=yfc_intf&operPasswd=yy123&agentCode=fs_nh_yfc&action=queryOnlineUserData&pageNumber=1&framedipaddress=192.168.0.131";
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
//同步post请求
NSURLResponse * response = nil;
NSError * error = nil;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *string = [[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@">>>>>>>>>%@",string);
//异步post请求
NSOperationQueue *MyQueue = [[NSOperationQueue alloc]init];
[NSURLConnection sendAsynchronousRequest:request queue:MyQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@">>>>>>>>>%@",string);
}];
}
get请求:
- (void)getRequest {
NSString *urlString = [NSString stringWithFormat:@"http://f1.netgears.cn:8081/cloudadmin_new/interface/commonQueryDataObject.action?opercode=yfc_intf&operPasswd=yy123&agentCode=fs_nh_yfc&action=queryOnlineUserData&pageNumber=1&framedipaddress=192.168.0.131"];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
//异步get请求
NSOperationQueue *MyQueue = [[NSOperationQueue alloc]init];
[NSURLConnection sendAsynchronousRequest:request queue:MyQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@">>>>>>>>>%@",string);
}];
//同步get请求
NSURLResponse * response = nil;
NSError * error = nil;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *string = [[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@">>>>>>>>>%@",string);
}