在做app应用的时候,需要将数据提交到服务器去存储,那么方法可以参考如下
来源:互联网 发布:java 字符型二维数组 编辑:程序博客网 时间:2024/05/17 08:11
http://www.gowhich.com/blog/186
//参数1名字=参数1数据&参数2名字=参数2数据&参数3名字=参数3数据&...NSString *postString = [NSString stringWithFormat:@"app_key=XXXXXXXXXXXXXXXXXX"];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&device_token=%@",deviceId]];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&teleplay_title=%@",title]];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&job_type=%@",type]];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&deadline=%@",time]];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&age=%@",age]];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&sex=%@",sex]];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&people_num=%@",num]];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&contact_person=%@",person]];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&contact=%@",phone]];postString = [postString stringByAppendingString:[NSString stringWithFormat:@"&description=%@",description]];NSLog(@"postString:%@",postString);//将NSSrring格式的参数转换格式为NSData,POST提交必须用NSData数据。NSData *postData = [postString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];//计算POST提交数据的长度NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];NSLog(@"postLength=%@",postLength);//定义NSMutableURLRequestNSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];//设置提交目的url[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.baidu.com"]]];//设置提交方式为 POST[request setHTTPMethod:@"POST"];//设置http-header:Content-Type//这里设置为 application/x-www-form-urlencoded ,如果设置为其它的,比如text/html;charset=utf-8,或者 text/html 等,都会出错。不知道什么原因。[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];//设置http-header:Content-Length[request setValue:postLength forHTTPHeaderField:@"Content-Length"];//设置需要post提交的内容[request setHTTPBody:postData];//定义NSHTTPURLResponse* urlResponse = nil;NSError *error = [[NSError alloc] init];//设置网络状态显示[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;//同步提交:POST提交并等待返回值(同步),返回值是NSData类型。NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];//将NSData类型的返回值转换成NSString类型// NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];//将NSData装换为字典类型NSError *jsonError = [[NSError alloc] init];NSDictionary *personDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&jsonError];NSString *status = [personDictionary objectForKey:@"status"];if ([@"ok" compare:status] == NSOrderedSame) { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; return YES;}return NO;
0 0
- 在做app应用的时候,需要将数据提交到服务器去存储,那么方法可以参考如下
- 在做app应用的时候,需要将数据提交到服务器去存储,那么方法可以参考如下
- 在做app应用的时候,需要将数据提交到服务器去存储,那么方法可以参考如下
- 需要解决post提交数据的时候,乱码的问题:在web.xml里做配置:
- 提交应用到苹果app store 需要注意的细节
- 今天在做项目的时候,用到了跨服务器导入数据 方法二
- C# 将字节流转换为图片的实例方法,需要的朋友可以参考一下
- app应用提交需要准备的材料
- QTP在录制脚本的时候会将鼠标点击过的对象自动添加到对象库中,而那些未被点击过的对象将不会被添加,导致针对某一对象手动添加的脚本运行不通过,因此需要手动把测试对象添加到对象库中,方法如下:
- 用ajax提交到后台方法,返回一个json数组,在前台怎么去将这个json数据读取出来放在table里面。
- 在facebook上做app, 需要提交privacy policy url的解决办法
- 在将视频转换成mp4格式的时候,需要做那些预设(presets)?
- Android提交数据到服务器的几种方法
- Android 提交数据到服务器的四种方法
- 利用js提交数据给服务器 可以很秘密的提交数据到服务器 运行会访问 一个gif文件
- 如果客户端提交的FQDN本服务器没有,那么禁止服务器会帮助客户端去查询
- 关于建立tensorflowOnspark时候,需要做的环境搭建,看如下链接的文章
- structs2.3在jsp提交数据到action时候的乱码的解决
- 找工作笔试面试那些事儿(15)---互联网公司面试的零零种种和多家经验
- 用指针的方式代替数组下标改写程序month_day
- 从头开始写项目Makefile(十):make内嵌函数及make命令显示
- QC11 premier Edition 安装注意事项
- IOS调试技巧:当程序崩溃的时候怎么办 iphone IOS
- 在做app应用的时候,需要将数据提交到服务器去存储,那么方法可以参考如下
- UISwitch开关控件
- 数据结构 第一章 绪论
- #翻译# 介绍后缀树(suffix tree)
- stack,heap,static
- 在做app应用的时候,需要将数据提交到服务器去存储,那么方法可以参考如下
- 记录在linux的/bin/目录下添加一个带有软连接的命令
- 猕猴桃 教你做猕猴桃虾球沙拉
- iOS系统Crash文件分析方法