简体   繁体   中英

NSURL set from variables

A pretty simple question i am sure, but i don't know how to go about doing such a thing. At current i $post variable 1 and variable 2 to the server and return some son data this is pretty slow but it worked, then it all went down hill when i started to have execution issues on the server side. Rented server so can't change php.ini file. So i have came up with this idea as a work around.

Would it be possible to direct to my download source, if the link itself contained variables collected from my label.text rather than writing each individual link out for each group (127 to be precise). For instance variable1 would equal "hell" and variable to would equal "red" therefore my NSURL would point to www.test.com/hell/red.php

Is this possible or is there some other way of doing this?

NSURL *url = [NSURL URLWithString:@"http://www.test.com/$variable1/$variable2.php"];

So now i know that this is possible, is some form or way, how can i resolve the following errors that i am receiving? For what i understand i simply can't have a / between the two variables and i can't have the .json file extension included on the end of the url. 在此处输入图片说明

在此处输入图片说明 If you require anymore code don't hesitate to ask.

Thank you very much in advance for any help!

The string you are creating the NSURL with is a normal NSString . To use variables in a NSString , you can use:

[NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2];

%@ is a placeholder for a string. variable1 and variable2 must be NSString s

The line that creates could look like this:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2]];

Or:

NSString * urlString = [NSString stringWithFormat:@"http://www.test.com/%@/%@.php", variable1, variable2];
NSURL * url = [NSURL URLWithString:urlString];

You can try this one:

NSString *urlString = [NSString stringWithFormat:@" http://www.test.com/%@/%@.php ", var1, var2];

NSURL *url = [NSURL URLWithString:urlString];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM