网络解析同步异步

/*------------------------get同步-------------------------------------*/

- (IBAction)GET_TB:(id)sender

{

//1.创建url

NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];

//2.创建一个请求对象

NSMutableURLRequest *requst = [NSMutableURLRequest requestWithURL:url];

//请求方式

[requst setHTTPMethod:@"get"];

NSURLResponse *response = nil;

NSError *err= nil;

//3.建立连接

NSData *data = [NSURLConnection sendSynchronousRequest:requst returningResponse:&response error:&err];

NSLog(@"%@",data);

NSLog(@"同步");

}

/*---------------------------get异步------------------------------------*/

- (IBAction)GET_YB:(id)sender

{

//1.创建url

NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];

//2.创建请求对象

NSURLRequest *requset = [NSURLRequest requestWithURL:url];

//3.建立连接

[NSURLConnection sendAsynchronousRequest:requset queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

NSLog(@"%@",data);

}];

NSLog(@"异步");

}

/*------------------------------post同步------------------------------------------*/

- (IBAction)POST_TB:(id)sender

{

//1.创建URL

NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];

//2.创建请求对象

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"post"];

//3.加入包体

NSString *str =@"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";

//将字符串转换成NSDATA格式

NSData *dataBody = [str dataUsingEncoding:NSUTF8StringEncoding];

//4.给请求设body

[request setHTTPBody:dataBody];

//5.创建连接

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

NSLog(@"%@",data);

NSLog(@"POST同步");

}

/*------------------------------post异步------------------------------------------*/

- (IBAction)POST_YB:(id)sender

{

//1.创建URL

NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];

//2.创建请求对象

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"post"];

//3.给请求对象加入body

NSString *bodyStr = @"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";

NSData *dataBody = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];

[request setHTTPBody:dataBody];

//4.创建连接

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

NSLog(@"%@",data);

}];

NSLog(@"POST异步");

}

/*------------------------get同步-------------------------------------*/
- (IBAction)GET_TB:(id)sender
{
//1.创建url
NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];
//2.创建一个请求对象
NSMutableURLRequest *requst = [NSMutableURLRequest requestWithURL:url];
//请求方式
[requst setHTTPMethod:@"get"];
NSURLResponse *response = nil;
NSError *err= nil;
//3.建立连接
NSData *data = [NSURLConnection sendSynchronousRequest:requst returningResponse:&response error:&err];
NSLog(@"%@",data);
NSLog(@"同步"); }
/*---------------------------get异步------------------------------------*/ - (IBAction)GET_YB:(id)sender
{
//1.创建url
NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];
//2.创建请求对象
NSURLRequest *requset = [NSURLRequest requestWithURL:url];
//3.建立连接
[NSURLConnection sendAsynchronousRequest:requset queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"%@",data);
}];
NSLog(@"异步");
} /*------------------------------post同步------------------------------------------*/ - (IBAction)POST_TB:(id)sender
{
//1.创建URL
NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];
//2.创建请求对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"post"];
//3.加入包体
NSString *str =@"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";
//将字符串转换成NSDATA格式
NSData *dataBody = [str dataUsingEncoding:NSUTF8StringEncoding];
//4.给请求设body
[request setHTTPBody:dataBody];
//5.创建连接
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"%@",data);
NSLog(@"POST同步"); }
/*------------------------------post异步------------------------------------------*/ - (IBAction)POST_YB:(id)sender
{
//1.创建URL
NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];
//2.创建请求对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"post"];
//3.给请求对象加入body
NSString *bodyStr = @"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";
NSData *dataBody = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:dataBody];
//4.创建连接
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"%@",data);
}];
NSLog(@"POST异步");
}

IOS 网络解析的更多相关文章

  1. 【读书笔记】iOS网络-解析响应负载

    Web Service可以通过多种格式返回结构化数据, 不过大多数时候使用的是XML与JSON.也可以让应用只接收HTML结构的数据.实现了这些Web Service或是接收HTML文档的应用必须能解 ...

  2. ios 网络数据下载和JSON解析

    ios 网络数据下载和JSON解析 简介 在本文中笔者将要给大家介绍ios中如何利用NSURLConnection从网络上下载数据,如何解析下载下来的JSON数据格式,以及如何显示数据和图片的异步下载 ...

  3. 【读书笔记】iOS网络-使用Bonjour实现自组织网络

    Bonjour就是这样一种技术:设备可以通过它轻松探测并连接到相同网络中的其他设备,整个过程只需要很少的用户参与或是根本就不需要用户参与.该框架提供了众多适合于移动的使用场景,如基于网络的游戏,设备间 ...

  4. 【读书笔记】iOS网络-三种错误

    一,操作系统错误. iOS人机界面指南中,Apple建议不要过度使用AlertViews,因为这会破坏设备的使用感受. 操作系统错误: 1,没有网络. 2,无法路由到目标主机. 3,没用应和监听目标端 ...

  5. 【读书笔记】iOS网络-负载

    负载指的是在服务的请求响应事务中交换的数据.常见的负载格式包括XML,JSON与HTML. 进入与发出的负载数据存在很多形式与大小.比如,有些开发者会使用原生的字符串或是以分隔符分开的数据与Web S ...

  6. 【读书笔记】iOS网络-同步请求,队列式异步请求,异步请求的区别

    一,同步请求的最佳实践. 1,只在后台过程中使用同步请求,除非确定访问的是本地文件资源,否则请不要在主线程上使用. 2,只有在知道返回的数据不会超出应用的内存时才使用同步请求.记住,整个响应体都会位于 ...

  7. ios网络学习------6 json格式数据的请求处理

    ios网络学习------6 json格式数据的请求处理 分类: IOS2014-06-30 20:33 471人阅读 评论(3) 收藏 举报 #import "MainViewContro ...

  8. iOS网络编程模型

    iOS网络编程层次结构也分为三层: Cocoa层:NSURL,Bonjour,Game Kit,WebKit Core Foundation层:基于 C 的 CFNetwork 和 CFNetServ ...

  9. iOS网络相关零散知识总结

    iOS网络相关零散知识总结 1. URL和HTTP知识 (1) URL的全称是Uniform Resource Locator(统一资源定位符). URL的基本格式 = 协议://主机地址/路径   ...

随机推荐

  1. val

    val 题目描述 有一个值初始为0,接下来n次你可以令其在之前基础上+2或+1或-1.你需要保证,这个值在整个过程中达到的最大值减去达到的最小值不大于k,求方案数,模1,000,000,007. 输入 ...

  2. Codeforces Round #316 (Div. 2) A 水

    A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  3. h5 video切换到横屏全屏

    将video设置为屏幕大小,覆盖其他元素,想到这种操作我也是震惊的 function() { let startIcon = document.getElementById('start-icon') ...

  4. white-space使用注意事项

    今天写移动端的时候有个地方需要横向滚动的功能,自然而然需要用到white-space这个属性了,但是试了一下发现没有效果,反复查找原因后,发现white-space是对inline-block起作用的 ...

  5. 解决当打开Unity时 提示项目已经打开,而自己之前并没有打开过(可能之前异常关闭)的问题

    当打开Unity时 提示项目已经打开,而自己之前并没有打开过(可能之前异常关闭) 发生这种情况时 打开项目目录中的 Temp文件夹,可以找到 一个 UnityLockfile 文件 将这个文件删除就可 ...

  6. 【HDOJ5536】Chip Factory(Trie树)

    题意:给定n个数字,第i个数字为a[i],求max((a[i]+a[j])^a[k]),其中i,j,k互不相同 n<=1000,0<=a[i]<=1e9 思路:队友写的,抱大腿 先对 ...

  7. 【转】Resharper上手指南

    原文发布时间为:2011-02-16 -- 来源于本人的百度文章 [由搬家工具导入] 我是visual studio的忠实用户,从visual studio 6一直用到了visual studio 2 ...

  8. 爬虫学习笔记(五) Beautiful Soup使用

    上篇博客说了正则表达式,但是正则学起来比较费劲,写的时候也不好写,这次说下Beautiful Soup怎么用,这个模块是用来解析html的,它操作很简单,用起来比较方便,比正则学习起来简单多了. 这是 ...

  9. 51nod 1006 最长公共子序列Lcs 【LCS/打印path】

    1006 最长公共子序列Lcs  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的). ...

  10. [Python Cookbook] Numpy: Iterating Over Arrays

    1. Using for-loop Iterate along row axis: import numpy as np x=np.array([[1,2,3],[4,5,6]]) for i in ...