NSMutableURLRequest,在POST方式下传递参数
1. [代码][C/C++]代码
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSLog(@"Load currentCookie:%@", cookie);
[request setValue:cookie forHTTPHeaderField:@"Cookie"];
[request setURL:[a objectAtIndex:0]];
[request setHTTPMethod:@"GET"];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
[request release];
2. [代码]一、iPhone终端代码:
NSString *post = nil;
post = [[NSString alloc] initWithFormat:@"message=%@",@"hello,world."];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://192.168.10.220:18080/data/1.jsp"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData]; 网站模板
//[NSURLConnection connectionWithRequest:request delegate:self ];
//同步请求的的代码
//returnData就是返回得到的数据
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningRequest:nil error:nil];
[post release];
3. [代码]二、web服务器端代码
<%
String message = request.getParameter("message");
System.out.println("message="+message);
out.println("message="+message);
%>
4. [代码]采用json 格式post 字符串
static NSString *urlString = @"http://192.168.1.103/WebAccess/admin/tablesSync.aspx";
//static NSString *urlString = @"http://www.google.cn";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
NSString *httpBodyString = @"a test string";
NSMutableArray *arrayData = [[NSMutableArray alloc] init];
NSMutableDictionary *dlist = [[NSMutableDictionary alloc] init];
[dlist setObject:@"tblArea" forKey:@"tableName"];
[dlist setObject:@"2009-10-24 11:20:00" forKey:@"lastChangeDate"];
[arrayData addObject:dlist];
//[request setHTTPBody:[httpBodyString dataUsingEncoding:NSUTF8StringEncoding]];
//
//post = [[NSString alloc] initWithFormat:@"message=%@",@"hello,world."];
httpBodyString = [arrayData JSONRepresentation];
NSData *postData = [httpBodyString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setHTTPBody:postData]; http://www.huiyi8.com/moban/
[request setHTTPMethod:@"POST"];
//
NSURLResponse *reponse;
NSError *error = nil;
//
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&reponse error:&error];
if (error) {
NSLog(@"Something wrong: %@",[error description]);
}else {
if (responseData) {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"get %@",responseString);
}
}
NSMutableDictionary *dgetData = [responseString JSONValue];
NSLog(@"dgetData: %@" , [dgetData description]);
[dlist release];
[arrayData release];
NSMutableURLRequest,在POST方式下传递参数的更多相关文章
- Jmeter在非GUI环境下传递参数(命令行&Jenkins配置)
https://www.cnblogs.com/kill0001000/p/8078686.html 通过cmd运行 jmeter -? 可以得到所有命令行选项(本文最后) 其中可以看到下面 -J 的 ...
- Android解惑 - 为什么要用Fragment.setArguments(Bundle bundle)来传递参数(转)
Fragment在Android3.0开始提供,并且在兼容包中也提供了Fragment特性的支持.Fragment的推出让我们编写和管理用户界面更快捷更方便了. 但当我们实例化自定义Fragmen ...
- C#传递参数调用exe程序
今天公司让我把Winform程序里的一块单独成一个exe文件,从原程序中打开新的exe程序,这就涉及到参数的传递,故来记录下传递参数到exe程序的方式 第一种方式 首先在程序A中添加引用using S ...
- hadoop传递参数方法总结
转自:http://blog.csdn.net/xichenguan/article/details/22162813 写MapReduce程序通常要传递各种各样的参数,选择合适的方式来传递参数既能提 ...
- C#传递参数
与函数交换数据的最好方式就是传递参数,在C#中有四种方法来控制参数如何传递给目标方法 C#中的参数修饰符 无修饰 如果一个参数没有用参数修饰符,则认为它将按值传递 out 输出参数由被调用的方法赋值. ...
- linux命令行传递参数定期执行PHP文件
最近在做一个项目,需要在linux下传递参数定期执行PHP文件,网上查询资料,确实有相关资料,现整理如下: 1.linux执行PHP文件 #{PHP安装bin路径} {PHP文件路径} {需要参数1 ...
- URL中传递参数给视图函数
1. 采用在url中使用变量的方式: 在path的第一个参数中,使用<参数名>的方式可以传递参数.然后在视图函数中也要写一个参数,视图函数中的参数必须和url中的参数名称保持一致,不然就找 ...
- centos shell编程4【分发系统】 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要同步的文件 expect文件分发系统 expect自动发送密钥脚本 Linux脚本执行方式 第三十八节课
centos shell编程4[分发系统] 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要 ...
- asp传递参数的几种方式
把下列代码分别加入a.asp和b.asp的<body></body>中,点提交,就可以将a.asp文本框的内容传给b.asp并显示出来 a.ASP <form actio ...
随机推荐
- erlang debugger
http://erlang.org/doc/apps/debugger/debugger_chapter.html
- 【postman】postman测试API报错如下:TypeError: Failed to execute 'fetch' on 'Window': Invalid value 对中文支持不好
使用postman测试APi的时候,因为系统需要在header部带上登录用户的信息,所以 如下: 然后测试报错如下:TypeError: Failed to execute 'fetch' on 'W ...
- 调用tensorflow中的concat方法时Expected int32, got list containing Tensors of type '_Message' instead.
grid = tf.concat(0, [x_t_flat, y_t_flat, ones])#报错语句 grid = tf.concat( [x_t_flat, y_t_flat, ones],0) ...
- Window10下Apache2.4的安装和运行
以前用Python运行的Web框架都是要运行在Linux下,加上WSGI服务器,比如Gunicorn+Flask,后来了解到了Apache,看看能不能基于Apache这个Web服务器下给python提 ...
- awk的求和计算使用;awk多个分隔符如何使用?
1.对于下图,如何使用awk求所有各列的和 和:175 16 78 19 方法:awk '{for(n=1;n<=NF;n++)t[n]+=$n}END{for(n=1;n<=NF;n++ ...
- asp .net 为图片添加图片水印 .
首先写好一个写入图片水印的类,先创建一个ImageWriter类库 (该类中有包含枚举类型和方法) using System; using System.Collections.Generic; ...
- Solaris 系统启动与关闭
忘掉root密码 更改内核参数后,重启进不了系统 复制---进入单用户模式----恢复文件 系统突然死机,如何尽量减少数据丢失 Sync 同步命令.将内存内容输入到硬盘,相当于保存文档. Unix ...
- C#数据类型与数据库字段类型对应
数据库 C#程序 int int32 text string bigint int64 binary System.Byte[] bit Boolean char string datetime Sy ...
- Centos 安装Puppet
环境说明: OS:CentOS 5.4 i386puppetmaster 192.168.0.12 hostname: puppetmaster.info.comclient ...
- 网页编程-django前传
1.js正则表达式 http://www.cnblogs.com/wupeiqi/articles/5602773.html test - 判断字符串是否符合规定的正则 正则表达式: rep = ...