4

How can I add GET parameters to an ASIHttpRequest?

I want to go from http://mysite.com/server to http://mysite.com/server?a=1&b=2 programmatically.

I have all my parameters as key-value pairs in an NSDictionary object.

Thanks

1

1 Answer 1

5

Use string format like

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); 
Sign up to request clarification or add additional context in comments.

1 Comment

It does not escape special characters.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.