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

                    

                }];

     

        }

  • 相关阅读:
    SEO优化---学会建立高转化率的网站关键词库
    从一个程序员的角度看——微信小应用
    当AngularJS POST方法碰上PHP
    angularJS(6)
    彻底解决显示Opencv中Mat图像到Mfc窗口问题
    数据结构与算法基础总结
    java类别问题
    java基础知识
    逻辑地址、线性地址、物理地址和虚拟地址的区别
    TCP协议中的三次握手和四次挥手(图解)
  • 原文地址:https://www.cnblogs.com/rollrock/p/5275898.html
Copyright © 2011-2022 走看看