ASI基本使用-同步请求

来源:互联网 发布:spring 启动加载数据 编辑:程序博客网 时间:2024/05/17 08:54

一、同步请求

@interface SNViewController ()@property(nonatomic, strong) ASIHTTPRequest *request;@end@implementation SNViewController- (void)viewDidLoad{    [super viewDidLoad];    [self sync];}-(void)sync{
    1.创建请求对象    NSURL *url = [NSURL URLWithString:@"http://wycx.55115511.cn:7766/vms/sys_car!execute.action?usersId=20140001"];    self.request = [ASIHTTPRequest requestWithURL:url];    
    2.发送请求    [self.request startSynchronous];    
    3.处理服务器返回的结果数据    if (self.request.error) {        NSLog(@"请求出错");    }else{        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:self.request.responseData options:NSJSONReadingMutableLeaves error:nil];        NSLog(@"%@", dict);    }}- (void)dealloc{    [super dealloc];    [self.request clearDelegatesAndCancel];}


0 0
原创粉丝点击