-
Notifications
You must be signed in to change notification settings - Fork 194
Request
zhuchao edited this page Mar 9, 2015
·
10 revisions
#Request
Request为初始化网络请求数据的类
- ###GET
如果你想发这样一个GET请求
http://test-leway.zjseek.com.cn:8000/api/goods/goodsList?type=1&pageSize=10&page=1&categoryId=-1&areaName=浙江
你可以这样定义一个GoodsListRequest
#import "Request.h"
@interface GoodsListRequest : Request
@property(nonatomic,retain) NSString *type;
@property(nonatomic,retain) NSNumber *page;
@property(nonatomic,retain) NSNumber *pageSize;
@property(nonatomic,retain) NSString *categoryId;
@property(nonatomic,retain) NSString *areaName;
@end
#import "GoodsListRequest.h"
@implementation GoodsListRequest
/**
* 初始化 GoodsListRequest 的参数
*/
-(void)loadRequest{
[super loadRequest];
//self.HOST = @"test-leway.zjseek.com.cn:8000"; 不设置host 就采用宏定义的全局host
self.PATH = @"/api/goods/goodsList";
self.METHOD = @"GET";
self.type = @"1";
self.categoryId = @"-1";
self.areaName = @"浙江";
self.pageSize = @10;
}
@end
loadRequest方法里面初始化HOST,PATH,METHOD以及各种变量。EasyIOS会自动进行拼接为`http://test-leway.zjseek.com.cn:8000/api/goods/goodsList?type=1&pageSize=10&page=1&categoryId=-1&areaName=浙江`
-
###POST 如果你想POST文件 你可以这样定义一个ImagePostRequest
#import "Request.h" @interface ImagePostRequest : Request @property(nonatomic,retain) NSString *name; @end #import "ImagePostRequest.h" @implementation ImagePostRequest /** * 初始化 GoodsListRequest 的参数 */ -(void)loadRequest{ [super loadRequest]; //self.HOST = @"test-leway.zjseek.com.cn:8000"; 不设置host 就采用宏定义的全局host self.PATH = @"/api/goods/goodsList"; self.METHOD = @"POST"; //设置为post self.name = @"图片"; NSString *localPath1 = [NSString stringWithFormat:@"%@/%@",$.documentPath,@"face1.png"]; NSString *localPath2 = [NSString stringWithFormat:@"%@/%@",$.documentPath,@"face2.png"]; self.requestFiles = @{@"image1":[NSURL fileURLWithPath:localPath1], @"image2":[NSURL fileURLWithPath:localPath2]}; } @end
requestFiles方法里面返回一个文件字典。EasyIOS会自动进行识别上传
-
###激活请求 如果你想快速的激活一个Request
self.sceneModel.request.requestNeedActive = YES;