在iPhone中从URL检索数据 [英] retrieving data from url in iphone

查看:48
本文介绍了在iPhone中从URL检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php页面,该页面连接到数据库并从具有GET参数的表中检索数据,假设一个人将检索给定颜色的衬衫列表:

i have a php page that connects to a database and retrieves data from a table given a GET parameter, suppose one would retrieve a list of shirts given a color:

从颜色= $ _GET [color;

select * from shirts where color = $_GET[color ;

我想让iphone向该页面发出请求(发送get参数)并检索该数据以便在我的应用中使用.

I want form the iphone to make a request to that page, (sending that get parameter) and retrieve that data for using it in my app.

我该怎么做?

谢谢!

推荐答案

可以使用 NSURLConnection 从URL检索数据.您为此类提供了一个 NSURLRequest ,它将尝试在后台获取数据.然后,使用委托方法,您可以响应"失败或成功.

Retrieving data from an URL can be done by using NSURLConnection. You provide this class a NSURLRequest and it will try to fetch the data in the background. Using delegate methods, you can then 'respond' to failures or success.

您可以这样创建 NSURLRequest :

//color is your color object
NSString *url = [NSString stringWithFormat:@"http://www.yoursite.com/yourpage.php?color=%@",color];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

(更多信息和示例)

这篇关于在iPhone中从URL检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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