GET POST通用的网络请求
2016-01-19 20:22
471 查看
(void) networkWithURL: (NSString *)urlStr success: (SuccessBlock)blo{
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *tesk = [session dataTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (data) {
id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
dispatch_async(dispatch_get_main_queue(), ^{
blo(obj);
});
}
}];
[tesk resume];
}
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *tesk = [session dataTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (data) {
id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
dispatch_async(dispatch_get_main_queue(), ^{
blo(obj);
});
}
}];
[tesk resume];
}
相关文章推荐
- oracle https://localhost:1158/em 无法打开
- XHR——XMLHttpRequest对象
- 通过/proc/net/dev分析网络包量,流量,错包,丢包
- 网络编程-TCP程序实例(client端heserver端相互通信)
- 1-6 网络层
- 深度学习(二十七)可视化理解卷积神经网络-ECCV 2014
- 网络编程-TCP程序实例(只是发送了数据,在服务器显示)
- 网络编程-UDP程序聊天小程序
- 使用中国CDN网络分发Unity网页插件的方法
- 使用 httpurlconnection 在android上post操作
- xcode7 创建新工程,兼容http
- 封装网络请求工具类
- http-equiv="X-UA-Compatible"
- 网络编程-UDP2
- (十五)httpClient、HttpUrlConnecttion调研总结
- HTTP状态码
- 计算机网络的各层的常用协议
- 网络篇-NSURLSession介绍
- In Gradle projects, always use http://schemas.android.com/apk/res-auto for custom attributes more..
- 自带finish清除网络请求的Activity