How to concatenate an nsstring url

2020-03-03 03:16发布

How can I concatenate an NSString URL? For example:

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

3条回答
戒情不戒烟
2楼-- · 2020-03-03 03:35

You can use the method stringWithFormat of NSString:

NSString *url = [NSString stringWithFormat:@"somewebsite.com/username=%@&password=%@", someuservariable, some variable];
查看更多
虎瘦雄心在
3楼-- · 2020-03-03 03:48

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

查看更多
Anthone
4楼-- · 2020-03-03 03:48

Try this excellent post - URL encoding an NSString on iOS

查看更多
登录 后发表回答