我正在创建一个应用程序,您在其中键入一个值到文本框中,应用程序向我的网络服务器发送HTTP GET请求,即www.mywebserver.server.com/ihiuahdiuehfiuseh?' + textbox variable'
但是,我不知道如何使用Xcode。我在基本的PHP和HTML以及高级C ++方面经验丰富,但我对这个Xcode的东西感到困惑。在我使用的所有其他语言中,你可以查找“如何在(语言)中播放声音文件”,你会得到类似“哦,是的,只是玩(mp3url)”。但是,使用Xcode,你我必须启动连接,启动变量等等。我买了2本30美元的书,但我仍然很困惑。所以,回到这一点,我只需要在URl之后解析文本框数字?被解析为变量。
答案 0 :(得分:1)
这是非http get synchronized
的示例您可以找到更多
-(void)aget:(NSString *)iurl{
NSURL*url = [NSURL URLWithString:iurl];
NSURLRequest *res = [NSURLRequest requestWithURL:url];
NSOperationQueue*que=[NSOperationQueue new];
[NSURLConnection sendAsynchronousRequest:res queue:que completionHandler:^(NSURLResponse*rep,NSData*data,NSError*err){
if ([data length]> 0 && err == nil) {
NSString* rel=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",rel);
}else{
NSLog(@"isnull");
}
}
];
}
NSString * str = [self getDataFrom: @ "your url"];
NSLog(@“%@”,str);
答案 1 :(得分:0)
如果您有UITextFiled
,则可以执行以下操作
NSString baseUrl = @"www.mywebserver.server.com/ihiuahdiuehfiuseh?"
NSString variable = textField.text;
NSString absoluteURL = [NSString stringWithFormat:@"%@%@", baseUrl, variable];
//Send the absolute variable now to the server
答案 2 :(得分:0)
如果你想找到像Omar Abdelhafith建议的解决方案,不要忘记对你的'querystring'进行网址编码。字符串类中有一个方法:“stringByAddingPercentEscapesUsingEncoding”,但它并不完美。
我最近使用了此处建议的解决方案:http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/。