AFNetworking 2.0和GET请求参数
问题描述:
我有一个问题关于AFNetworking 2.0AFNetworking 2.0和GET请求参数
我不得不做出这样的GET请求:
http://myhost.come/entity?language=en&query=$UserId=14 and $EntityCreationDate>'2014-09-01'
如何生成此请求的字典参数?
我特别不明白我怎么能建立这个:and $EntityCreationDate>'2014-09-01'
答
在这里,我找到了一个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];