zoukankan      html  css  js  c++  java
  • AFNetWorking 使用记录

    1.从一个URL  GET数据

    方法1:

            NSURL * url = [NSURL URLWithString:@"http://www.weather.com.cn/data/sk/101010100.html"];

            NSURLRequest * req = [NSURLRequest requestWithURL:url];

            AFHTTPRequestOperation * oper = [[AFHTTPRequestOperation alloc]initWithRequest:req];

            [oper setCompletionBlockWithSuccess:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {

                NSLog(@"succ:%@",operation.responseString);            

            } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {

                

                NSLog(@"fail:%@",error);

            }];

            

            NSOperationQueue * q = [NSOperationQueue new];

            [q addOperation:oper];

     

      方法2:      

            AFHTTPRequestOperationManager * m = [AFHTTPRequestOperationManager manager];

            m.responseSerializer = [AFHTTPResponseSerializer serializer];

            [m GET:@"http://www.weather.com.cn/data/sk/101010100.html" parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {

                

                NSLog(@"succ:%@",operation.responseString);

                

            } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {

                

                NSLog(@"fail:%@",error);

                

            }];

     

    2.POST

      

            AFHTTPRequestOperationManager * m = [AFHTTPRequestOperationManager manager];

            m.responseSerializer = [AFHTTPResponseSerializer serializer];

            

            NSMutableDictionary * d = [NSMutableDictionary new];

            [d setValue:@"白羊座" forKey:@"consName"];

            [d setValue:@"today" forKey:@"type"];

            [d setValue:@"8e8cb4ebeb7bbc14449fc62e6fe1ed7f" forKey:@"key"];

            

            

            [m POST:@"http://web.juhe.cn:8080/constellation/getAll" parameters:d success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {

                

                    

                    NSLog(@"succ:%@",operation.responseString);

                    

                } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {

                    

                    NSLog(@"fail:%@",error);

                    

                }];

     

        }

  • 相关阅读:
    css三角形拼接多边形
    弹框提示Request failed with status code 401
    el-upload组件上传闪动
    vue-element-admin校验不通过 页面跳到滚动位置
    请求方式错误
    IE兼容11支持10不支持
    二次封装elementui弹框
    element多张上传的去除动画
    奇怪的知识增加了,python切片特点以及下标的活用,可变tuple
    LeafHttp,同步、异步请求的Http库
  • 原文地址:https://www.cnblogs.com/rollrock/p/5275898.html
Copyright © 2011-2022 走看看