application/x-www-form-urlencoded(AFNetwork 方式实现)
来源:互联网 发布:申请淘宝店铺多少钱 编辑:程序博客网 时间:2024/06/16 03:42
前言
提交后台的数据格式:
Post 方式提交
key=value&key=value&key=value
正文
1、拼接字符串
- (NSMutableString*) stringWithkey:(NSString *)key value:(NSString*)value{ [self appendString:[NSString stringWithFormat:@"%@=%@",key,value]]; return self;} [strFrom stringWithkey:@"Operator" value:@""];//运营商名称
2、将字符串转NSData
NSData *myPostData = [strFrom dataUsingEncoding:NSUTF8StringEncoding]; NSMutableData *myMutablePostData = [NSMutableData dataWithData:myPostData]; dict[CMPAYHttpParamsPostBodykey] = myMutablePostData;
3、将请求数据data进行提交
/ 1/封装NSMutableURLRequest NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; request.HTTPMethod = @"POST"; request.HTTPBody = params;// 2/ AFHTTPSessionManager 创建NSURLSessionDataTask AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];// mgr.responseSerializer = [AFHTTPResponseSerializer serializer];//返回数据以xml格式接收 //设置返回的数据是JSON格式 mgr.responseSerializer = [AFJSONResponseSerializer serializer];//返回数据以json格式接收 // mgr.requestSerializer = [AFHTTPRequestSerializer serializer]; [mgr.requestSerializer setValue:@"gzip, deflate" forHTTPHeaderField:@"Accept-Encoding"]; [mgr.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; mgr.requestSerializer.timeoutInterval = 30.0;
阅读全文
1 0
- application/x-www-form-urlencoded(AFNetwork 方式实现)
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- application/x-www-form-urlencoded
- Form元素application/x-www-form-urlencoded
- application/x-www-form-urlencoded 字符编码
- Content-Type: application/x-www-form-urlencoded
- 关于application/x-www-form-urlencoded编码
- 关于application/x-www-form-urlencoded
- application/x-www-form-urlencoded multipart/form-data text/plain
- Python实现北邮人论坛模拟登录
- HDU6112今夕何夕(Java写法)
- linux apache
- Leetcode557. Reverse Words in a String III
- python可变参数和可改变对象
- application/x-www-form-urlencoded(AFNetwork 方式实现)
- netty拆包粘包问题处理
- 编程题
- PS 的基本使用
- 线程基础函数
- 线段树模板
- 水池数目(bfs模板题)
- 关注国情民情——华北水利水电大学“情艺”国情社情调研团
- C语言(一)--开发步骤,注释,gcc