AFNetWorking网络请求
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网络请求的更多相关文章
- AFNetworking网络请求与图片上传工具(POST)
AFNetworking网络请求与图片上传工具(POST) .h文件 #import <Foundation/Foundation.h> /** 成功Block */ typedef vo ...
- iOS - AFNetworking 网络请求
前言 在 iOS 开发中,一般情况下,简单的向某个 Web 站点简单的页面提交请求并获取服务器的响应,用 Xcode 自带的 NSURLConnection 是能胜任的.但是,在绝大部分下我们所需要访 ...
- AFNetworking网络请求的get和post步骤
1.首先通过第三方:CocoaPods下载AFNetworking 1.1.先找到要查找的三方库:pod search + AFNetworking 1.2.出来一堆列表页面,选择三方库最新版本命 ...
- AFNetworking网络请求数据
//创建AFNetworking的请求操作 AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWit ...
- 设置AFNetworking网络请求的超时时间
http://www.mamicode.com/info-detail-511816.html // 设置超时时间 [manager.requestSerializer willChangeValue ...
- iOS应用内抓包、NSURLProtocol 拦截 APP 内的网络请求
前言 开发中遇到需要获取SDK中的数据,由于无法看到代码,所以只能通过监听所有的网络请求数据,截取相应的返回数据,可以通过NSURLProtocol实现,还可用于与H5的交互 一.NSURLProto ...
- CHNetRequest网络请求
Paste JSON as Code • quicktype 软件的使用 iOS开发:官方自带的JSON使用 JSON 数据解析 XML 数据解析 Plist 数据解析 NetRequest 网络数据 ...
- iOS开发--Swift 基于AFNetworking 3.0的网络请求封装
Swift和OC基于AFNetworking的网络请求流程相同, 就是语法不同, 对于Swift语法不是很清楚的同学, 建议多看看API文档, 自己多多尝试. 写过OC的应该都明白每句话做什么的, 就 ...
- 网络请求的基本知识《极客学院 --AFNetworking 2.x 网络解析详解--1》学习笔记
网络请求的基本知识 我们网络请求用的是HTTP请求 Http请求格式:请求的方法,请求头,请求正文 Http请求的Request fields:请求的头部,以及被请求头部的一些设置 Http请求的 ...
随机推荐
- Android学习总结——去除标题栏
1.继承app.Activity的Activity去除标题栏 @Override protected void onCreate(Bundle savedInstanceState) { super. ...
- Android设备的ID
Android的开发者在一些特定情况下都需要知道手机中的唯一设备ID.例如,跟踪应用程序的安装,生成用于复制保护的DRM时需要使用设备的唯一ID.在本文档结尾处提供了作为参考的示例代码片段. 范围 本 ...
- uva 310 L--system(隐式图搜索+字符串处理)
L-system A D0L (Deterministic Lindenmayer system without interaction) system consists of a finite ...
- [Immutable.js] Lightning Fast Immutable.js Equality Checks with Hash Codes
While Immutable.js offers .is() to confirm value equality between iterables it comes at the cost of ...
- SlipButton——滑动开关
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjI1MjUwMg==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- html5 video播放不全屏
<video controls="controls" webkit-playsinline src="${page.videoUrl }" type=&q ...
- css-文字
<!DOCTYPE html>CSS2-文字 <style>div{ /*文字*/ font-size:120px; /*文字大小*/ font-family:Arial,'方 ...
- hbase权威指南学习笔记--过滤器
1.使用hbase是shell客户端进行过滤查询 scan 'testtable',{COLUMNS=>'colfam1:col-0',FILTER=>RowFilter.new(Comp ...
- Winform开发之窗体传值
Winform的窗体之间的数据传递是开发的必备技术,下面介绍几种典型的传值方法 1.构造函数传值,但这种方法是单向的(推荐) 上代码,先传值 private void button2_Click(ob ...
- jQuery_easyUI 合并单元格 (DataGrid 数据表格)
<table id="dg" style="height:350px;z-index:-5555; " class="easyui-datagr ...