[2014-03-27]iOS内置库POST异步

NSURL *url = [NSURL URLWithString:@"http://192.168.0.196:8088/zjt_frameesb/api/info"];

    NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:

                         @"c30e1a88-bab8-4296-a128-23c12476ee2f",@"typeid",

                         @"b0ffd1414d78752b7591a0a6f4543ee8",@"applycode",

                         nil];

    NSDictionary *sendDic = [[NSDictionary alloc] initWithObjectsAndKeys:

                             dic,@"data",

                             @"b0ffd1414d78752b7591a0a6f4543ee8",@"system",

                             @"zjt_content",@"method",

                             @"ios",@"source",

                             nil];

    NSData *data = [NSJSONSerialization dataWithJSONObject:sendDic options:NSJSONWritingPrettyPrinted error:nil];

    NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    [request setHTTPMethod:@"POST"];

    

    

    

    NSString *body = [[NSString stringWithFormat:@"data="] stringByAppendingString:jsonString];

    NSLog(@"\n%@",body);

    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];

    NSOperationQueue *queue = [[NSOperationQueue alloc] init];


    [request setTimeoutInterval:100.0];

    

    [NSURLConnection sendAsynchronousRequest:request

                                       queue:queue

                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){

                               if (error) {

                                   NSLog(@"Httperror:%@%d", error.localizedDescription,error.code);

                               }else{

                                   

                                   NSInteger responseCode = [(NSHTTPURLResponse *)response statusCode];

                                   

                                   NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

                                   

                                   NSLog(@"HttpResponseCode:%d", responseCode);

                                   NSLog(@"接受加密数据 %@",responseString);

                                   NSString *decodeUrl = [responseString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

                                   NSLog(@"解密数据:%@",decodeUrl);


                                   NSString *encodeUrl = [decodeUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

                                   NSLog(@"加密数据:%@",encodeUrl);

                               }

                           }];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值