[iOS 多线程 & 网络 - 2.6] - 使用POST上传JSON数据 & 多值参数
//
// ViewController.m
// PostJsonDemo
//
// Created by hellovoidworld on 15/1/28.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "ViewController.h" @interface ViewController ()
- (IBAction)postJson; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (IBAction)postJson {
// 1.创建请求
NSURL *url = [NSURL URLWithString:@"http://192.168.0.21:8080/MyTestServer/acceptJson"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
// 设置post发送
request.HTTPMethod = @"POST"; // 2.设置请求头
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; // 3.设置请求体
NSDictionary *json = @{@"name":@"tom",
@"age":@""};
request.HTTPBody = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil]; // 4.发送请求
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"%@", [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil]);
}]; }
@end
[iOS 多线程 & 网络 - 2.6] - 使用POST上传JSON数据 & 多值参数的更多相关文章
- [iOS 多线程 & 网络 - 2.11] - ASI框架上传文件
A.ASI的上传功能基本使用 1.实现步骤 (1)创建请求 使用ASIFormDataRequest (2)设置上传文件路径 (3)发送请求 2.上传相册相片 UIImagePickerCon ...
- [iOS 多线程 & 网络 - 2.5] - 小文件上传
A.文件上传 思路: 发送文件数据给服务器 使用post请求 必须手动设置请求头: 内容大小Content-Length & 内容类型 Content-Type 请求体:文件数据 文件上传的格 ...
- POST 上传 JSON 数据
// // ViewController.m // 03-post上传json // // Created by jerry on 15/10/10. // Copyright (c) 2015年 j ...
- springmvc04-文件上传-JSON数据
文件上传部分: 1, 导入commons-fileupload-1.2.2.jar commons-io-2.4.jar 两个jar包. 2, 在主配置文件中,添加如下信息 <!-- 文件上传- ...
- php curl 上传json数据
PUT $data = array('username'=>'dog','password'=>'tall'); $data_json = json_encode($data); $ch ...
- C语言采用socket实现http post方式上传json数据
1.按照HTTP协议发送请求: http POST 报文格式 http 报文是面向文本的. 报文分为:请求报文和响应报文 请求报文由:请求行,请求头部,空行和请求数据四个部分组成. <1.请求行 ...
- HttpUrlConneciton上传JSON数据
try { //创建连接 URL url = new URL(url); HttpURLConnection connection = (HttpURLConnection) url.openConn ...
- xUtils怎么post请求上传json数据
InfoSmallCodeBinding smallCode = new InfoSmallCodeBinding(); smallCode.setSmallCode("测试"); ...
- Android开发之从网络URL上下载JSON数据
网络下载拉取数据中,json数据是一种格式化的xml数据,非常轻量方便,效率高,体验好等优点,下面就android中如何从给定的url下载json数据给予解析: 主要使用http请求方法,并用到Htt ...
随机推荐
- Python模块整理(三):子进程模块subprocess
文章 原始出处 http://ipseek.blog.51cto.com/1041109/807513. 本来收集整理网络上相关资料后整理: 从python2.4版本开始,可以用subprocess这 ...
- Android 按键消息处理Android 按键消息处理
在android系统中,键盘按键事件是由SystemServer服务来管理的:然后在以消息的形式分发给应用程序处理.产生键盘按键事件则是有Linux kernel的相关驱动来实现. 键盘消息有别于其他 ...
- uva11181Probability|Given
枚举,条件概率. 2^20次方等于100w,是大约可以没准还能过的. 二进制枚举时,如果买东西的人恰好为r个,设概率为p,就将sum[i]+=p(sum[i]为r个人买东西时第i个人买东西的概率),t ...
- Java [Leetcode 337]House Robber III
题目描述: The thief has found himself a new place for his thievery again. There is only one entrance to ...
- ubuntu 安装 ia32-libs
很多软件只有32位的,有的依赖32位库还挺严重的:从ubuntu 13.10已经废弃了ia32-libs,但可以使用多架构,安装软件或包apt-get install program:i386.有的还 ...
- ubuntu12.04上搭建darwin streaming server6.03
个人建议:使用DarwinStreamingSrvr5.5.5,因为DarwinStreamingSrvr6.0.3安装过程中有很多问题需要解决!而且安装只需执行./Install就可以! 1:下载d ...
- 使用carrierwave出现MiniMagick::Invalid错误的解决方法
安装Imagemagick不能从源码安装,要从软件市场安装,否则会出现错误:MiniMagick::Invalid 使用make uninstall卸载后,重新在软件市场里安装,问题解决.
- android左右滑动加载分页以及动态加载数据
android UI 往右滑动,滑动到最后一页就自动加载数据并显示 如图: package cn.anycall.ju; import java.util.ArrayList; import java ...
- How to easily create popup menu for DevExpress treelist z
http://www.itjungles.com/how-to-easily-create-popup-menu-for-devexpress-treelist.html Adding popup m ...
- 在Ubuntu下卸载Apache
卸载Apache 转自:http://blog.csdn.net/chmo2011/article/details/7026384 1. 删除apache 代码: $ sudo apt-get --p ...