ASIHTTPRequest-插件的使用

一、什么是ASIHTTPRequest

ASIHTTPRequest 插件是一个开源的第三方网络请求相关的插件!目前大多数关于网络请求的操作,我都使用它,简单,适用,方便,高效,给力!!!

二、集成ASIHTTPRequest

1、下载ASIHTTPRequest 插件包。
下载地址:https://github.com/pokeb/asi-http-request/tree
2、加入到项目中。
3、在需要使用ASIHTTPRequest相关功能的页面中,加入头文件(.h文件)的引用。

#import "ASIHTTPRequest.h"

#import "ASIFormDataRequest.h"// POST 方式需要引入

4、引入相应的框架包。

 CFNetwork、SystemConfiguration、MobileCoreServices、 libz、 libxml2


三、Get方式请求Demo

还是直接贴代码吧!!!

-(void) Request_GET

{

    NSString* urlString = [NSString stringWithFormat:@"Your_URL"];

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURLURLWithString:urlString]];

    [request setDefaultResponseEncoding:NSUTF8StringEncoding];

    [request setResponseEncoding:NSUTF8StringEncoding];

    [request setTimeOutSeconds:15.0f];//5s超时

    [request setCompletionBlock:^{


    NSString* hexString = [request responseString];

            

        

    }];

    

    [request setFailedBlock:^{

        

    }];

    

[request startSynchronous];// 同步请求

    //    [request startAsynchronous];// 异步请求

}


四、POST方式请求Demo

 

- (void) Request_POST{


   NSString *appid = @"22222";

    NSString* urlString = [NSString stringWithFormat:@"https://graph.qq.com/t/add_t"];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURLURLWithString:urlString]];

    [request setPostValue:[_tencentOAuth accessTokenforKey:@"access_token"];

    [request setPostValue:[_tencentOAuth openIdforKey:@"openid"];

    [request setPostValue:appid forKey:@"oauth_consumer_key"];

    [request setPostValue:@"json" forKey:@"format"];

    [request setPostValue:@"You_Content" forKey:@"content"];

    

    [request setDelegate:self];

    [request setTimeOutSeconds:30.0f];//5s超时

    [request setCompletionBlock:^{

        NSLog(@"sucess");

        NSString* hexString = [request responseString];

        

        NSLog(@"%@",hexString);

    

    

    }];

    [request setFailedBlock:^{

         NSLog(@"Failed");

        

    }];

    

    [request startAsynchronous];


}


先mark 到这里吧,以后用得到的地方,在慢慢深入!

希望对你有所帮助!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值