标签:
链接地址:http://blog.sina.com.cn/s/blog_7b9d64af0101e5uf.html
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"// POST 方式需要引入
CFNetwork、SystemConfiguration、MobileCoreServices、 libz、 libxml2
-(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];// 异步请求
}
- (void) Request_POST{
NSString *appid = @"22222";
NSString* urlString = [NSStringstringWithFormat:@"https://graph.qq.com/t/add_t"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURLURLWithString:urlString]];
[request setPostValue:[_tencentOAuth accessToken] forKey:@"access_token"];
[request setPostValue:[_tencentOAuth openId] forKey:@"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];
}
标签:
原文地址:http://www.cnblogs.com/wvqusrtg/p/4831206.html