ASIHTTPRequest发送异步GET请求
/**
* 异步的GET请求
*/
- (void)touchesBegan:(NSSet*)touches
withEvent:(UIEvent*)event
{
//
获取URL
NSURL *url = [NSURLURLWithString:@"http://192.168.15.56:8080/MJServer/login?username=123&pwd=123"];
//
创建一个请求对象
ASIHTTPRequest *request = [ASIHTTPRequestrequestWithURL:url];
request.timeOutSeconds=
15;// 15秒后超时
//
设置代理
request.delegate=
self;
//
开始请求
[request
startAsynchronous];
}
#pragma mark -实现
/**
*
开始请求
*/
- (void)requestStarted:(ASIHTTPRequest*)request
{
NSLog(@"requestStarted");
}
/**
*
接收服务器返回的响应头信息
*/
- (void)request:(ASIHTTPRequest*)request
didReceiveResponseHeaders:(NSDictionary*)responseHeaders
{
NSLog(@"%@",responseHeaders);
NSLog(@"didReceiveResponseHeaders");
}
/**
*
请求结束
*/
- (void)requestFinished:(ASIHTTPRequest*)request
{
NSLog(@"%@",request);
NSLog(@"requestFinished");
}
/**
*
请求失败
*/
- (void)requestFailed:(ASIHTTPRequest*)request
{
NSLog(@"requestFailed");
}
- (void)requestRedirected:(ASIHTTPRequest*)request
{
NSLog(@"requestRedirected");
}
/**
*
接收服务器返回的数据
*/
- (void)request:(ASIHTTPRequest*)request
didReceiveData:(NSData*)data
{
//
解析数据
NSDictionary * dict = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingMutableLeaveserror:nil];
NSString *error = dict[@"error"];
NSLog(@"%@",error);
NSString *success = dict[@"success"];
NSLog(@"%@",success);
NSLog(@"didReceiveData");
}ASIHTTPRequest发送异步GET请求
原文:http://blog.csdn.net/itcontend/article/details/41809509