浅谈HTTP 中get 和post方式
来源:互联网 发布:iphone7怎么样 知乎 编辑:程序博客网 时间:2024/06/05 09:24
Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE。URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP中的GET,POST,PUT,DELETE就对应着对这个资源的查,改,增,删4个操作。到这里,大家应该有个大概的了解了,GET一般用于获取/查询资源信息,而POST一般用于更新资源信息。
最常用的也就是get和post 下面讲一下get和post请求
get方法效率高 传输快 但缺点却是安全性差
post方法效率低 传输相对慢 但是安全性却很好
1.get方法
//get 方法
[self getMethod];
2.实现get方法- (void)getMethod
{
//取得请求操作的manager
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
//响应序列化
manager.responseSerializer = [AFHTTPResponseSerializerserializer];
//设置服务器响应内容的类型
manager.responseSerializer.acceptableContentTypes = [NSSetsetWithObject:@"text/html"];
NSString *path =@"http://www.weather.com.cn/data/cityinfo/101010100.html";
[managerGET:path parameters:nilsuccess:^(AFHTTPRequestOperation *operation,id responseObject) {
NSDictionary *dict = [NSJSONSerializationJSONObjectWithData:responseObject options:NSJSONReadingMutableContainerserror:nil];
NSLog(@"dict = %@",dict);
NSDictionary *weatherinfo = dict[@"weatherinfo"];
NSString *city = weatherinfo[@"city"];
NSLog(@"city = %@",city);
}failure:^(AFHTTPRequestOperation *operation,NSError *error) {
NSLog(@"error = %@",error.localizedDescription);
}];
}
3.post方法//post 方法
[selfpostMethod];
- (void)postMethod
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
NSString *url =@"http://10.0.8.8/sns/my/login.php";
NSDictionary *dict =@{@"username":@"leaf_s",@"password":@"222222"};
// NSLog(@"%@",dict);
//响应序列化
manager.responseSerializer = [AFHTTPResponseSerializerserializer];
//设置服务器响应内容的类型
manager.responseSerializer.acceptableContentTypes = [NSSetsetWithObject:@"text/html"];
[managerPOST:url parameters:dictsuccess:^(AFHTTPRequestOperation *operation,id responseObject) {
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:responseObject options:NSJSONReadingMutableContainerserror:nil];
NSLog(@"dic = %@",dic);
NSString *message = dic[@"message"];
NSLog(@"message = %@",message);
}failure:^(AFHTTPRequestOperation *operation,NSError *error) {
NSLog(@"error = %@",error.localizedDescription);
}];
}
- 浅谈HTTP 中get 和post方式
- 浅谈HTTP中get和post的区别
- 浅谈HTTP中Get和Post的区别
- 浅谈HTTP中Get和Post的区别
- 浅谈Http中GET和POST的区别
- 浅谈HTTP中GET和POST的区别
- 浅谈HTTP中 GET 与 POST 区别
- 浅谈HTTP的GET和POST请求
- 浅谈HTTP GET POST
- Http GET和Http Post发送方式
- HTTP中Get和Post方式的区别
- HTTP中Get和Post方式的区别
- HTTP请求中如何选择Get和Post方式
- HTTP请求中如何选择Get和Post方式
- HTTP请求中如何选择Get和Post方式
- HTTP 中 Get 和Post
- http中 post和get
- http中Post、Get方式的区别
- FERET 人脸识别技术测试的简单介绍
- Qt: QT中PRO文件写法的详细介绍
- 开源 java CMS - FreeCMS2.4 热词管理
- sqlite3:基本操作
- HTML:通信设置界面刷新失败原因分析
- 浅谈HTTP 中get 和post方式
- leetcode-T7 Reverse digits of an integer
- Http1.0和http1.1
- VirtualBox下安装CentOS,安装图解
- linux下tar、zip等压缩、解压命令
- mysql 中 character set 与 collation 的点滴理解
- php json中文乱码问题
- HTML:highcharts绘制折线图
- EL表达式