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

                    

                }];

     

        }

  • 相关阅读:
    今天写一篇随想,也当是回顾过去,展望未来吧。
    推荐 Word、EXCEL必备工具箱
    elasticsearch Routing 路由详解
    Python学习之字典
    ES 分片和副本数 调整及数据写入、重建索引调优
    fastJson JSON.parseObject()丢失字符串原本顺序
    Python 列表(详)
    pycharm常用快捷键
    Python学习笔记二(列表)
    python学习笔记二
  • 原文地址:https://www.cnblogs.com/rollrock/p/5275898.html
Copyright © 2011-2022 走看看