ASIHttpRequst 之异步请求
来源:互联网 发布:微信无法打开淘宝链接 编辑:程序博客网 时间:2024/06/07 00:51
//
// RootViewController.m
// ASIHttpRequest
//
// Created by Hallin_Me on 14-10-7.
// Copyright (c) 2014年 hallin_me. All rights reserved.
//
/*
使用方法:
ASIHttpRequst第三方类库 不支持arc
使用前导入下面4个系统包
libz.1.1.3.dylib,MobileCoreServices.framework,SystemConfiguration.framework,CFNetwork.framework
*/
#define URL_PATH @"http://sp.autohome.com.cn/clubapp/jingxuan/HomeJingHua.ashx?pageSize=20&pageIndex=0"
#import "RootViewController.h"
#import "ASIHTTPRequest.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
//ASI请求
[selfcreateASIHttp];
self.view.backgroundColor=[UIColorredColor];
}
-(void)createASIHttp{
//封装URL
NSURL *url=[NSURLURLWithString:URL_PATH];
//创建ASIHttp请求对象
ASIHTTPRequest *request=[ASIHTTPRequestrequestWithURL:url];
//协议
request.delegate=self;
//开始请求,开启异步请求
[request startSynchronous];
}
#pragma mark ASIHTTPRequestDelegate
-(void)requestStarted:(ASIHTTPRequest *)request{
NSLog(@"开始请求!");
}
-(void)request:(ASIHTTPRequest *)request didReceiveResponseHeaders:(NSDictionary *)responseHeaders{
NSLog(@"建立联系!");
}
-(void)requestFinished:(ASIHTTPRequest *)request{
// NSString *str=[[NSString alloc]initWithData:request.responseData encoding:NSUTF8StringEncoding];
// NSLog(@"%@",str);
//如若上面NSUTF8StringEncoding格式转换没用,链接的数据使用的GBK格式,所以data数据要格式转换
NSStringEncoding gbkEncoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString *str=[[NSStringalloc]initWithData:request.responseDataencoding:gbkEncoding];
NSLog(@"%@",str);
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- ASIHttpRequst 之异步请求
- Ajax之异步请求
- NSURLSessionConfiguration之异步请求
- Spring-MVC异步请求之Servlet异步
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- IOS之同步请求、异步请求、GET请求、POST请求
- asp.net 在线聊天室
- 阶乘因式分解
- SGU 104 Little shop of flowers(DP)
- STM32 在MDK SRAM调试的问题
- 自己写双链表
- ASIHttpRequst 之异步请求
- 华为机试题, 换乘。抛砖引玉
- java开发医疗信息管理系统源代码下载
- acdream 1427 Nice Sequence
- [Leetcode]Longest Consecutive Sequence
- 《关于减肥你应该知道的十件事》
- 第十七章 17.1.2节练习
- dat文件如何导入mysql数据库
- 【C++】CLRS上的堆排序实现