【问题标题】:AFNetworking 2.0 and GET Request parametersAFNetworking 2.0 和 GET 请求参数
【发布时间】:2014-09-06 13:18:38
【问题描述】:
我有一个关于 AFNetworking 2.0 的问题
我必须发出这样的 GET 请求:
http://myhost.come/entity?language=en&query=$UserId=14 and $EntityCreationDate>'2014-09-01'
如何为这个请求生成字典参数?
特别是我不明白如何构建这个:and $EntityCreationDate>'2014-09-01'
【问题讨论】:
标签:
ios
objective-c
get
afnetworking-2
【解决方案1】:
在这里我找到了good tutorial。
这表明一个简单的 GET 请求可以这样发送:
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://samwize.com/"]];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
path:@"http://samwize.com/api/pigs/"
parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Print the response body in text
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];