English 中文(简体)
检索电传中的尿素数据
原标题:retrieving data from url in iphone
  • 时间:2010-01-09 16:49:02
  •  标签:
  • iphone

i 设有一个与数据库连接的站点网页,并在考虑到GET参数的情况下从一个桌上检索数据。

* 选自彩色 =美元_GET[color ;

我想形成一线电话,要求该页面(接收参数),并检索该数据,供我使用。

如何这样做?

感谢!

最佳回答

可通过<>NSURLConnection检索URL的数据。 您提供<条码>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];

(More information and an example)

问题回答

最简单的办法是使用

NSString *url = [NSString stringWithFormat:@"http://www.yoursite.com/yourpage.php?color=%@",color];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];

由于有了<代码>NSURLRequest,你必须做一些更多的魔术才能获得实际数据。

如果你想要从NSData获得一个NSString,就使用

NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// ...
[response release]; // do this somewhere or you ll have a mem-leak!




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签