How to concatenate an nsstring url

谁说胖子不能爱 提交于 2019-12-30 06:41:06

问题


How can I concatenate an NSString URL? For example:

http://isomewebsite.com/username=[someuservariable]&password=[somevariable]

回答1:


Try with below code.

NSString* myURLString = [NSString stringWithFormat:@"somewebsite.com/username=%@&password=%@", myUserName,myPassword];
NSURL *url = [NSURL URLWithString:myURLString];

Here is the blog tutorial will help you know more about Handling url authentication challenges accessing password protected servers




回答2:


You can use the method stringWithFormat of NSString:

NSString *url = [NSString stringWithFormat:@"somewebsite.com/username=%@&password=%@", someuservariable, some variable];



回答3:


Try this excellent post - URL encoding an NSString on iOS



来源:https://stackoverflow.com/questions/5741095/how-to-concatenate-an-nsstring-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!