I am developing one app in that app I need pass more than one parameters at a time in NSURL my code is
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 it is, then how? thanks & regards
try creating a separate string 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 URL
NSURL *url = [NSURL URLWithString:strURL];
finally add it to the request, your code is wrong where you adding url to request, URL is not a string it is a URL so it should be requestWithURL
not URLWithString
, it should be like this
NSURLRequest *request = [NSURLRequest requestWithURL:url];
One thing many of these answers is missing is the use of [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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With