How to pass multiple parameters in NSURL string in iOS?

I am developing one application in this application. I need to pass multiple parameters at a time to NSURL in my code

responseData = [[NSMutableData data] retain]; ArrData = [NSMutableArray array]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://rate-exchange.appspot.com/currency?from=%@&to=%@&q=%@",strfrom,strto,strgo]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; //NSURLRequest *request1 = [NSURLRequest requestWithURL: //[NSURL URLWithString:@"http://rate-exchange.appspot.com/currency?from=%@&to=%@&q=1",strfrom,strto]]; 

the above code I need to pass more than one parameter Dynamically. Is it possible? if so, then how? thank you and welcome

+6
source share
2 answers

try creating a separate line before adding to the url something like

  NSSString *strURL=[NSString stringWithFormat:@"http://rate-exchange.appspot.com/currency?from=%@&to=%@&q=%@"‌​,strfrom,strto,strgo]; 

and then add this strURL to the url

 NSURL *url = [NSURL URLWithString:strURL]; 

finally add it to the request, your code is incorrect when you add the URL for the request, the URL is not a string, it is a URL, so it should be requestWithURL not URLWithString , it should be like that

 NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
+5
source

One of many of these answers is missing, this is using [NSString stringByAddingPercentEscapesUsingEncoding:] to avoid using invalid characters in the url:

 NSString *baseURL = [NSString stringWithFormat:@"http://rate-exchange.appspot.com/currency?from=%@&to=%@&q=%@",strfrom,strto,strgo]; NSURL *url = [NSURL URLWithString:[baseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
+1
source

All Articles