使用异步Post在新浪发微博
来源:互联网 发布:数据监控的技术方案 编辑:程序博客网 时间:2024/05/16 15:53
</pre><pre name="code" class="objc">#import "ViewController.h"@interface ViewController ()<NSURLConnectionDataDelegate>{ NSMutableData *mPostData;}@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (IBAction)asynchronousPost:(id)sender { //获取url NSString *urlString = @"https://api.weibo.com/2/statuses/update.json"; //编码 urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; //转换成NSURL NSURL *url = [NSURL URLWithString:urlString]; //oc中用 NSMutableURLRequest 进行Post请求 NSMutableURLRequest *mAsynRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10]; //获取参数 NSString *bobyString = @"status=Rock%20and%20roll&access_token=2.00bUKyMD0Spw_tebfe20df130tHaM_"; //编码 NSData *data = [bobyString dataUsingEncoding:4]; //方法体设置 [mAsynRequest setHTTPMethod:@"POST"]; [mAsynRequest setHTTPBody:data]; //连接 NSConnection *connectionPost = [NSURLConnection connectionWithRequest:mAsynRequest delegate:self];}#pragma mark-----------------------------------////服务器开始响应,准备向客户发送数据-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ mPostData = [NSMutableData data];}//从服务器接收数据,并且此方法会执行很多次-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ [mPostData appendData:data];}//接收数据完成-(void)connectionDidFinishLoading:(NSURLConnection *)connection{ //Json数据格式解析,利用系统提供的API进行Json数据解析 NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:mPostData options:NSJSONReadingAllowFragments error:nil]; // NSLog(@"%@",dictionary);}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
1 0
- 使用异步Post在新浪发微博
- 使用异步Get在新浪微博上获取最新的微博
- Ajax使用POST方式异步提交数据
- 【iOS-网络】使用异步的post请求
- POST异步请求方式(使用代理)
- OkHttp的使用--GET/POST(异步)
- 在新浪,在新浪
- 在.Net中使用异步
- 使用HttpWebRequest的POST取得网页内容(异步操作)
- 使用Block对POST异步操作的简单封装,NSURLConnection
- C#、Asp.net 使用 WebClient Get Post(同步、异步)
- django中使用ajax(post)进行异步请求
- jQuery.post( url, [data], [callback], [type] ) : 使用POST方式来进行异步请求
- 异步POST请求
- iOS 异步POST
- IOS异步请求 post
- get post 同步 异步
- Post同步异步
- 【高斯消元】BZOJ 1770: [Usaco2009 Nov]lights 燈
- tutorialspoint 教程之《Web Services 指南》
- socket实现简单文件传输系统
- Handler、Looper、MessageQueue、Message
- 正则表达式
- 使用异步Post在新浪发微博
- html 冷门
- ASP.NET MVC - Redirect-and-Post-JSON-Object-in-ASP-NET-MVC
- SIM908和STM32数据上传到上位机
- 【线段树/数学/扩展欧几里得】 Bzoj 3913:奇数国
- smart 和 dumb组件
- 在 iOS 9 中运行企业版应用
- SSH断开后重新连接
- xcode7、iOS9 设置启动图片(Launch Image)