欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

AFNetWorking网络请求

发布时间:2023/12/18 编程问答 51 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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网络请求的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。