如何将GET参数添加到ASIHttpRequest?
我想以编程方式从http://mysite.com/server
转到http://mysite.com/server?a=1&b=2
。
我将所有参数作为NSDictionary对象中的键值对。
由于
答案 0 :(得分:5)
使用字符串格式,如
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"1",@"a",@"2",@"b", nil];
NSMutableString *prams = [[NSMutableString alloc] init];
for (id keys in dict) {
[prams appendFormat:@"%@=%@&",keys,[dict objectForKey:keys]];
}
NSString *removeLastChar = [prams substringWithRange:NSMakeRange(0, [prams length]-1)];
NSString *urlString = [NSString stringWithFormat:@"http://mysite.com/server?%@",removeLastChar];
NSLog(@"urlString %@",urlString);