OC学习里面的一些概念(二)
2015-03-02 08:35
253 查看
同步post请求
第一步:创建url
NSString * url = [NSString UrlWithString:@"http://api.hudong.com/iphonexml.do"];
第二步:创建网络请求(参数和地址分开)
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[request setHTTPMethod:@"POST"];//设置请求方式为POST,默认为GET
NSString * str = @"type=focus-c";//设置参数
NSData * data = [str dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
第三步:连接服务器
NSData * received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString * str1 = [[NSString alloc] initWithData:received encoding:NSUTF8StringEncoding];
NSLog(@"%@",str1);
第一步:创建url
NSString * url = [NSString UrlWithString:@"http://api.hudong.com/iphonexml.do"];
第二步:创建网络请求(参数和地址分开)
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[request setHTTPMethod:@"POST"];//设置请求方式为POST,默认为GET
NSString * str = @"type=focus-c";//设置参数
NSData * data = [str dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
第三步:连接服务器
NSData * received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString * str1 = [[NSString alloc] initWithData:received encoding:NSUTF8StringEncoding];
NSLog(@"%@",str1);
相关文章推荐
- OC学习里面的一些概念(五)
- OC学习里面的一些概念(七)
- OC学习里面的一些概念(一)
- OC学习里面的一些概念(一)
- OC学习里面的一些概念(八)
- OC学习里面的一些概念(三)
- OC学习里面的一些概念(六)
- OC学习里面的一些概念(四)
- 黑马程序员-IOS学习笔记 OC 关于对象方法类方法的一些概念
- 一起学习Silverlight企业应用2:开始使用Silverlight,以及一些基本概念
- js的一些常用控制div的概念学习(重要)
- 图像、帧、片、NALU 是学习 H.264 的人常常感到困惑的一些概念,我在这里对自己的理解做一些阐述,欢迎大家讨论:
- C++一些概念--学习
- 学习Java的一些基本概念,一定要掌握哦~
- [HEVC] HEVC学习(二) —— HM的整体结构及一些基本概念
- Intellij Idea学习——一些常见概念
- javascript学习笔记(二) js一些基本概念
- 一些AOP的相关概念学习
- HEVC学习(二) —— HM的整体结构及一些基本概念
- oc 的一些概念