ios-GET和POST
来源:互联网 发布:阿里云计算机有限公司 编辑:程序博客网 时间:2024/06/08 02:21
// HTTP协议/* 1、HTTP是Hypertext Transfer Protocol的缩写,即超文本传输协议。网络中使用的基本协议是TCP/UDP协议,目前广泛采用的HTTP、HTTPS、FTP、Archie和Gropher等都是建立在TCP/UDP协议之上的应用层协议。 2、HTTP协议支持C/S网络结构,是无连接协议,即每一次请求时建立连接,服务器处理完客户端的请求之后,应答给客户端然后断开连接,不会一直占用网络资源。 3、HTTP协议共定义了8种请求方法:OPTIONS、HEAD、GET、POST、PUT、DELETE、TRACE、和CONNECT。作为Web服务器,必须实现GET和HEAD方法,其它方法都是可选的。 */// HTTPS协议/* 1、HTTPS是Hypertext Transfer Protocol Secure的缩写,即超文本传输安全协议,是超文本传输协议和SSL的组合,用以提供加密通信及对网络服务器身份的鉴定。 2、HTTPS使用https://,而HTTP使用http://;HTTPS使用端口443,而HTTP使用80. */// HTTP/HTTPS中的GET和POST方法/* 1、GET方法是向指定的资源发出请求,发送的消息“显式”地跟在URL后面。GET方法应该只用在读取数据,例如静态图片等。GET方法有点像使用明信片给别人信写信,“信内容”写在外面,接触到的人都可以看到,因此是不安全的。 2、POST方法是向指定的资源提交数据,请求服务器进行处理,例如提交表单或者上传文件等。数据被包含在请求体中。POST方法像是把“信内容”装入信封中,接触到的人是看不到的,因此是安全的。 */// 同步GET(Synchro GET)- (void)SynchroGet:(id)sender{ NSString *str = [NSString stringWithFormat:@"http://iosbook1.com/service/mynotes/webservice.php?email=%@&type=%@&action=%@",@"chenximincool@163.com",@"JSON",@"query"];//数据显示在链接中:email=%@&type=%@&action=%@",@"chenximincool@163.com",@"JSON",@"query NSURL *url = [NSURL URLWithString:str]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; // 同步请求 NSLog(@"请求完成!--data:%@",data);}// 异步GET(Asynchro GET)- (void)AsynchroGet:(id)sender{ NSString *str = [NSString stringWithFormat:@"http://iosbook1.com/service/mynotes/webservice.php?email=%@&type=%@&action=%@",@"chenximincool@163.com",@"JSON",@"query"]; NSURL *url = [NSURL URLWithString:str]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSURLConnection *connect = [[NSURLConnection alloc] initWithRequest:request delegate:self]; // 异步请求}// 异步POST(Asynchro POST)- (void)AsynchroPOST:(id)sender{ NSString *str = [NSString stringWithFormat:@"http://iosbook1.com/service/mynotes/webservice.php"]; NSString *post = [NSString stringWithFormat:@"email=%@&type=%@&action=%@",@"chenximincool@163.com",@"JSON",@"query"]; NSData *data = [post dataUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL URLWithString:str]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:data]; NSURLConnection *connect = [[NSURLConnection alloc] initWithRequest:request delegate:self]; // 异步请求}// 异步代理- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ NSLog(@"didReceiveData--%@",data);}- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ NSLog(@"didFailWithError--%@",[error localizedDescription]);}- (void)connectionDidFinishLoading:(NSURLConnection *)connection{ NSLog(@"connectionDidFinishLoading--请求完成!");}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning];}
0 0
- ios-GET和POST
- iOS http get和post
- iOS POST和GET传值
- iOS http get和post
- iOS NSURLConnection GET和POST
- iOS GET和POST对比
- iOS网络编程 GET和POST
- iOS http get和post(2)
- iOS http get和post(3)
- ios发送http GET和POST请求
- iOS 之get和post请求
- iOS 发送GET和POST网络请求
- iOS http get和post(2)
- iOS http get和post(3)
- iOS 中GET 和 POST 请求
- iOS GET请求和POST请求
- iOS中GET 和 POST 数据请求
- iOS 的GET和post请求
- windows路径分隔符
- 王者归来:什么情况下技术型CEO应该重新出山?
- c++参数传递方法
- asgterisk sip nat localnet externaddr externhost qualify
- 正铉函数画动态波浪图
- ios-GET和POST
- Spark源码阅读笔记:Spark集群中各个角色介绍
- SDUTOJ 2712 5-2 派生类的构造函数
- Update视图数据(oracle)
- 排序算法
- VS2012 快捷键
- Run Loop详解
- 斐波那契数列-矩阵乘法
- UIImageView userInteractionEnabled