iPhone-网络的应用

在iPhone中的网络应用分get和post方式,get方式一般用在获取少量数据后在对数据解析,获取的数据一般可以解析成xml和json,然后提出有用的数据。iPhone API中的NSString 提供了stringWithContentsofUrl:它使用同步连接,在执行期间,应用程序暂停,直到下载完成,所以不适合获取大的数据。一般方法为:

Object -C
1 +(NSString*) getResponseStringWithURL:(NSString*)urlString
2 {
3     NSURL *url = [NSURL URLWithString:urlString];
4     NSError *error;
5     NSString *responseString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
6     
7     return responseString ;
8 }


 

posted @ 2010-06-20 19:06  kallen  阅读(459)  评论(0编辑  收藏  举报