ASI框架使用全集讲解

ASI框架使用全集讲解,第1张

概述ASI框架使用全集讲解

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

#import "VIEwController.h"#import "ASIhttpRequest.h"#import "ASIFormDataRequest.h"#import "DACircularProgressVIEw.h"@interface VIEwController ()<ASIhttpRequestDelegate>@property(nonatomic,strong) NSMutableData  *data;@property(nonatomic,weak) DACircularProgressVIEw * da;@end@implementation VIEwController- (NSMutableData *)data{    if (_data==nil) {        _data=[NSMutableData data];    }    return _data;    }- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];        self.vIEw.backgroundcolor=[UIcolor greencolor];        DACircularProgressVIEw * da=[[DACircularProgressVIEw alloc] initWithFrame:CGRectMake(0,100,100)];        self.da=da;    self.da.center=self.vIEw.center;    [self.vIEw addSubvIEw:da];    }-(voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    //1 ASI 同步get请求//    [self _synGet];        //2 ASI 异步get请求//    [self _asynGet];        //3 ASI 异步get请求(block)//    [self _asynGetBlock];        //4 ASI 同步Post请求//     [self _synPost];        //5 ASI 异步Post请求//    [self _asynPost];        // 6ASI 下载//    [self _downLoad];        // 7ASI 上传    [self _upLoad];        }//同步get请求- (voID)_synGet{    NSURL * url=[NSURL URLWithString:@"http://localhost/logo.PHP?username=jereh&pwd=123"];        //1 封装请求    ASIhttpRequest * request=[[ASIhttpRequest alloc] initWithURL:url];    //2 发送请求    [request startSynchronous];    //3 获取响应数据    NSData * data=request.responseData;    Nsstring * result=[[Nsstring alloc] initWithData: data enCoding:NSUTF8StringEnCoding];    NSLog(@"%@",result);    }//异步get请求- (voID)_asynGet{            NSURL * url=[NSURL URLWithString:@"http://localhost/logo.PHP?username=jereh&pwd=123"];        //1 封装请求    ASIhttpRequest * request=[[ASIhttpRequest alloc] initWithURL:url];        request.delegate=self;        //2 发送请求    [request startAsynchronous];            }//异步get请求block- (voID)_asynGetBlock{            NSURL * url=[NSURL URLWithString:@"http://localhost/logo.PHP?username=jereh&pwd=123"];        //1 封装请求    ASIhttpRequest * request=[[ASIhttpRequest alloc] initWithURL:url];        //2 发送请求    [request startAsynchronous];            //3 重写block     [request setDataReceivedBlock:^(NSData *data) {         [self.data appendData:data];     }];         [request setheadersReceivedBlock:^(NSDictionary *responseheaders) {          }];        [request setFailedBlock:^{            }];            [request setCompletionBlock:^{        Nsstring * str=  [[Nsstring alloc] initWithData:self.data enCoding:NSUTF8StringEnCoding];        NSLog(@"%@",str);    }];    }//同步Post请求block- (voID) _synPost{            NSURL * url=[NSURL URLWithString:@"http://localhost/loginPost.PHP"];        ASIFormDataRequest * form=[[ASIFormDataRequest alloc] initWithURL:url];        //设置请求参数    [form setPostValue:@"jereh" forKey:@"username"];    [form setPostValue:@"123" forKey:@"pwd"];    [form startSynchronous];        Nsstring * str= form.responseString;    NSLog(@"%@",str);    }//同步Post请求block- (voID) _asynPost{         NSURL * url=[NSURL URLWithString:@"http://localhost/loginPost.PHP"];        ASIFormDataRequest * form=[[ASIFormDataRequest alloc] initWithURL:url];        //设置请求参数    [form setPostValue:@"jereh" forKey:@"username"];    [form setPostValue:@"123" forKey:@"pwd"];    form.delegate=self;       [form startSynchronous];}- (voID) _downLoad{     NSURL * url=[NSURL URLWithString:@"http://localhost/test.rar"];        //1 封装请求    ASIhttpRequest * request=[[ASIhttpRequest alloc] initWithURL:url];        //2 dest path   Nsstring *path=[NSSearchPathForDirectorIEsInDomains(NSCachesDirectory,NSUserDomainMask,YES) lastObject];    path =[path stringByAppendingPathComponent:@"new.rar"];    NSLog(@"%@",path);        request.downloadDestinationPath=path;        request.downloadProgressDelegate=self.da;        //3 请求    [request startAsynchronous]; }//上传- (voID) _upLoad{        NSURL * url=[NSURL URLWithString:@"http://localhost/upload.PHP"];        ASIFormDataRequest * form=[[ASIFormDataRequest alloc] initWithURL:url];            Nsstring * path=[[NSBundle mainBundle] pathForResource:@"default.png" ofType:nil];        //设置文件参数    [form setfile:path withfilename:@"new.png" andContentType:@"image/png" forKey:@"file"];         form.uploadProgressDelegate=self.da;        [form startAsynchronous];}#pragma mark - ASIhttpRequest代理- (voID)request:(ASIhttpRequest *)request dIDReceiveData:(NSData *)data{    [self.data appendData:data]; }- (voID)request:(ASIhttpRequest *)request dIDReceiveResponseheaders:(NSDictionary *)responseheaders{}- (voID)requestFinished:(ASIhttpRequest *)request{    Nsstring * str=  [[Nsstring alloc] initWithData:self.data enCoding:NSUTF8StringEnCoding];    NSLog(@"%@",str);}- (voID)requestFailed:(ASIhttpRequest *)request{}@end 

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的ASI框架使用全集讲解全部内容,希望文章能够帮你解决ASI框架使用全集讲解所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1106461.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存