在 Objective-C 中构建 URL [英] Building up a URL in Objective-C

查看:88
本文介绍了在 Objective-C 中构建 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向不同的服务器发出请求我只想在文本字段中填写 url 或 ip 地址.我构建了不同的解决方案,但它们都失败了.我想我很接近这个.

I want to make a request to diffrent servers I only want to fill in the url or ip address in a textfield. I build different solutions but they all faild. I think with this one i'm close.

这是我目前构建的:

NSString *part0 = @"http://";
NSString *part1 = [NSString stringWithFormat:@"%@" , _serveradres.text ];
NSString *part2 = @"/API/";
NSString *compURL = [NSString stringWithFormat:@"%@" , part0 , part1 , part2 ];

NSURL *url = [NSURL URLWithString:compURL];



ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

只是地址不一样,api都在同一个地方.

Only the address is diffrent, the api's are all ways on the same place.

稍后我想做一个可以选择http或https的开关

Later on i want to make a switch that can choose http or https

推荐答案

你应该改变这个:

NSString *compURL = [NSString stringWithFormat:@"%@" , part0 , part1 , part2 ];

为此:

NSString *compURL = [NSString stringWithFormat:@"%@%@%@" , part0 , part1 , part2 ];

因为现在您的 compURL 将只是 http://

Because now your compURL would be just http://

希望能帮到你

这篇关于在 Objective-C 中构建 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆