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

                    

                }];

     

        }

  • 相关阅读:
    .net MVC 下载文件乱码问题解决方案
    javascript将json转字符串
    js中将字符串转换成json的三种方式
    mvc项目,导出到Excel,中文显示乱码
    20160606面试题总结
    bzoj 4318: OSU!
    bzoj 1419: Red is good
    Codeforces 123 E Maze
    HDU 4336 Card Collector
    Codeforces 540 D Bad Luck Island
  • 原文地址:https://www.cnblogs.com/rollrock/p/5275898.html
Copyright © 2011-2022 走看看