ASIRequest的GET_POST请求数据
- (void)request:(NSString *)method params:(NSDictionary *)params
{
// NSString *urlstring = @"https://api.douban.com/v2/movie/top250";
NSString *urlstring =@"http://piao.163.com/m/cinema/schedule.html?app_id=1&mobileType=iPhone&ver=2.6&channel=appstore&deviceId=9E89CB6D-A62F-438C-8010-19278D46A8A6&apiVer=6&city=110000";
NSURL *url = [NSURL URLWithString:urlstring];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
request.requestMethod = method;
request.timeOutSeconds =30;
//https://api.douban.com/v2/movie/top250?t1=xxx&t2=ddd&t3.....
if ([method isEqualToString:@"GET"]) {
//1.GET请求将请求参数拼接到URL后面
//t1=xxx&t2=ddd&t3........
NSMutableString *parmastring = [NSMutableString string];
NSArray *allkeys = [params allKeys];
for (int i=0; i<[paramscount]; i++) {
NSString *key = [allkeys objectAtIndex:i];
NSString *value = [params objectForKey:key];
[parmastringappendFormat:@"%@=%@",key,value];
if (i<params.count-1) {
[parmastringappendString:@"&"];
}
}
urlstring = [NSString stringWithFormat:@"%@?%@",urlstring,parmastring];
NSURL *url = [NSURL URLWithString:urlstring];
request.url = url;
}else{
//2.POST将请求参数放在请求体中
for (NSString *keyin params) {
NSString *value = [params objectForKey:key];
//将请求参数添加到请求体中
[requestaddPostValue:value forKey:key];
}
NSLog(@"request=%@",request);
}
[request setCompletionBlock:^{
NSLog(@"request=%@",request);
NSLog(@"%@",request.responseString);
}];
[request startAsynchronous];
}