ios http请求

-(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);
        
         }];
}

-(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);
    
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值