AFNetWorking网络请求
生活随笔
收集整理的這篇文章主要介紹了
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;@endNetWorkAPIClient.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;
}@endHttpRequestService.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){}];
}
?
轉載于:https://www.cnblogs.com/joesen/p/3564499.html
總結
以上是生活随笔為你收集整理的AFNetWorking网络请求的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2014年2月份第3周51Aspx源码发
- 下一篇: iOS进阶之正则表达式