星空网 > 软件开发 > 操作系统

ASIHttpRequest加载网络数据和上传数据功能

使用ASIHttpRequest第三库,需要配置

ASIHttpRequest加载网络数据和上传数据功能images/loading.gif' data-original="http://images.cnitblog.com/blog2015/741122/201504/291748359749265.png" />ASIHttpRequest加载网络数据和上传数据功能

二,

上传数据功能使用ASIFromDataRequest(可以上传二进制和字符串给服务器)

下面来牛刀小试

//建立一个工程,导入第三方库,在AppDelegate.h#import <UIKit/UIKit.h>#import "ASIFormDataRequest.h"@interface AppDelegate : UIResponder <UIApplicationDelegate,ASIHTTPRequestDelegate>{  //声明数据请求的成员变量  ASIFormDataRequest *_request;}@property (strong, nonatomic) UIWindow *window;@end

//在AppDelegate.m里写的代码//通过POST请求加载数据NSURL *url=[NSURL URLWithString:@"http://10.0.8.8/sns/my/login.php"];//实例化成对象_request=[[ASIFormDataRequest alloc]initWithURL:url];//设置请求方式[_request setRequestMethod:@"post"];//添加参数[_request addPostValue:@"aa_Zx" forKey:@"username"];[_request addPostValue:@"ffff" forKey:@"password"];//设置代理回调_request.delegate=self;//请求数据[_request startAsynchronous];//异步请求,多线程

#param -mark ASIHttpRequest-(void)requestFinished:(ASIHTTPRequest *)request{NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];  NSLog(@"%@",dict);}- (void)requestFailed:(ASIHTTPRequest *)request{  NSLog(@"请求失败");}

 三,加载网络数据,ASIHttpRequest(所有格式的数据都能加载)

-(void)startLoadWebData:(NSString *)strURL{//实例化ASIHttpRequest对象NSURL *url=[NSURL URLWithString:strURL];_request=[[ASIHTTPRequest alloc]initWithURL:url];_requent.delegate=self;//开始加载数据[_requenst startAsynchronous];}#pragma -mark ASIHttpRequestDelegate//请求成功时调用该方法-(void)requestFinished:(ASIHTTPRequest *)request{NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:request.responseDataoptions:NSJSONReadingMutableContainers error:nil];//代理接收数据[self.delegate reciveData:[dict objectForKey:@"application"];}//请求网络数据失败时调用该方法-(void)requestFailed:(ASIHTTPRequest *)request{NSLog(@"failed");}

 




原标题:ASIHttpRequest加载网络数据和上传数据功能

关键词:网络

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流