NetWorkAPIClient.h
#import <Foundation/Foundation.h>
#import "AFHTTPRequestOperationManager.h" #define POST_PATH @"/campus/dispatch.rpc"
#define BASE_URL @"http://192.168.0.102:8080/idc/mobile/"//测试环境 @interface NetWorkAPIClient : AFHTTPRequestOperationManager + (NetWorkAPIClient *)sharedClient; @end NetWorkAPIClient.m
#import "NetWorkAPIClient.h" @implementation NetWorkAPIClient + (NetWorkAPIClient *)sharedClient {
static NetWorkAPIClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[NetWorkAPIClient alloc] initWithBaseURL:[NSURL URLWithString:BASE_URL]];
}); return _sharedClient;
} @end HttpRequestService.h
typedef void (^SuccessBlock)(id result);
typedef void (^FailedBlock)(NSError *error); + (void)postTest:(SuccessBlock)success failed:(FailedBlock)failed; HttpRequestService.m
#import "NetWorkAPIClient.h"
+ (void)postTest:(SuccessBlock)success failed:(FailedBlock)failed
{
NSDictionary *parameters=[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@",@"xxx"],@"userId",
[NSString stringWithFormat:@"%@",nil],@"userName",
[NSString stringWithFormat:@"%d",xxx],@"type",nil];
[[NetWorkAPIClient sharedClient] POST:GET_USER_INFO_PATH parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
success(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
} // 使用
-(void)requestUserInfoTest
{ [HttpRequestService postTest:^(id result)
{
NSDictionary *dataDic = result;
NSLog(@"dataDic %@",dataDic); }failed:^(NSError *error)
{ }];
}

AFNetWorking网络请求的更多相关文章

  1. AFNetworking网络请求与图片上传工具(POST)

    AFNetworking网络请求与图片上传工具(POST) .h文件 #import <Foundation/Foundation.h> /** 成功Block */ typedef vo ...

  2. iOS - AFNetworking 网络请求

    前言 在 iOS 开发中,一般情况下,简单的向某个 Web 站点简单的页面提交请求并获取服务器的响应,用 Xcode 自带的 NSURLConnection 是能胜任的.但是,在绝大部分下我们所需要访 ...

  3. AFNetworking网络请求的get和post步骤

      1.首先通过第三方:CocoaPods下载AFNetworking 1.1.先找到要查找的三方库:pod search + AFNetworking 1.2.出来一堆列表页面,选择三方库最新版本命 ...

  4. AFNetworking网络请求数据

    //创建AFNetworking的请求操作    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWit ...

  5. 设置AFNetworking网络请求的超时时间

    http://www.mamicode.com/info-detail-511816.html // 设置超时时间 [manager.requestSerializer willChangeValue ...

  6. iOS应用内抓包、NSURLProtocol 拦截 APP 内的网络请求

    前言 开发中遇到需要获取SDK中的数据,由于无法看到代码,所以只能通过监听所有的网络请求数据,截取相应的返回数据,可以通过NSURLProtocol实现,还可用于与H5的交互 一.NSURLProto ...

  7. CHNetRequest网络请求

    Paste JSON as Code • quicktype 软件的使用 iOS开发:官方自带的JSON使用 JSON 数据解析 XML 数据解析 Plist 数据解析 NetRequest 网络数据 ...

  8. iOS开发--Swift 基于AFNetworking 3.0的网络请求封装

    Swift和OC基于AFNetworking的网络请求流程相同, 就是语法不同, 对于Swift语法不是很清楚的同学, 建议多看看API文档, 自己多多尝试. 写过OC的应该都明白每句话做什么的, 就 ...

  9. 网络请求的基本知识《极客学院 --AFNetworking 2.x 网络解析详解--1》学习笔记

    网络请求的基本知识   我们网络请求用的是HTTP请求 Http请求格式:请求的方法,请求头,请求正文 Http请求的Request fields:请求的头部,以及被请求头部的一些设置 Http请求的 ...

随机推荐

  1. 《Java程序员面试笔试宝典》之为什么需要public static void main(String[] args)这个方法

    public staticvoid main(String[] args)为Java程序的入口方法,JVM在运行程序的时候,会首先查找main方法.其中,public是权限修饰符,表明任何类或对象都可 ...

  2. hdu 5288 OO’s Sequence(计数)

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  3. VIm变成sublime (转)

    sublime在ubuntu下始终支持不是很好, 特别是对中文输入的支持,还有一些插件在ubuntu下也不能用. 在ubuntu下还是用vim吧.  我们一起把vim变成sublime. 只需要三步 ...

  4. Linux shell编程 4 ---- shell中的循环

    1 for循环 1 for语句的结构 for variable in values; do statement done 2 for循环通常是用来处理一组值,这组值可以是任意的字符串的集合 3 for ...

  5. ACM-简单题之Ignatius and the Princess II——hdu1027

    转载请注明出处:http://blog.csdn.net/lttree Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Othe ...

  6. 向html某个元素中添加信息

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  7. 【问题备注】VS2012不能输入代码,文字…

    第一次遇到,非常奇怪,一个项目,VS2012能正常打开,但是不能输入代码. 对比分析发现,其他项目能正常work.在于一个问题就是,VS2012 右下角有个INS一直在转一直analyzing,而正常 ...

  8. CSS---------------之文本颜色

    CSS2支持如下名字的颜色 注意点: 你的浏览器有可能支持更多名字,但是在实际用的过程中尽量少使用名字的,因为各个浏览器对颜色的会存在差异:查看颜色可以参考 对于更多地颜色,你可以使用代表红,绿,蓝三 ...

  9. C++实现二叉树的基本操作

    #include <iostream> #include <stack> #include <queue> using std::cin; using std::c ...

  10. UI开发学习中遇到的问题汇总

    1.给UIView设置圆角,边框,阴影绘制,需要使用layer 1)设置圆角cornerView.layer.cornerRadius = 20; //设置试图圆角的大小cornerView.laye ...