江北书生的博客

如果有一天, 让你心动的再也感动不了你,让你愤怒的再也激怒不了你,让你悲伤的再也不能让你流泪,你便知道这时光,这生活给了你什么,你为了成长,付出了什么。

导航

什么时候该用ASIHTTPRequest,什么时候该用ASIFormDataRequest怎么判断

1、
NSString *postURL = [NSStringstringWithFormat:@"http://xxxxxx.php?model=%@&data=%@", myModel, myAllData];
NSLog(@"发送注册请求URL:%@", postURL);
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:postURL]];
[request startSynchronous];


2、


NSString *postURL = [NSStringstringWithFormat:@"http://xxxxxx.php"];
ASIFormDataRequest *request = [[ASIFormDataRequestalloc] initWithURL:[NSURLURLWithString:postURL]];
[request addPostValue:myModel forKey:@"model"];
[request addPostValue:myAllData forKey:@"data"];
[request startSynchronous];


发送一个注册请求,为什么用1的写法直接执行if([request error]),用2就执行if(![request error])啊????


什么时候该用ASIHTTPRequest,什么时候该用ASIFormDataRequest怎么判断啊???

==========================================================================

1. 如果是 Get ,或者参数可以简单的组成 Get 方式提交的时候, 比如  thread.php?id=123 , 就用  ASIHTTPRequest 就可以了
    原因是简单

2. 如果必须是 POST ,或者参数很多,你要构造一个带参数的 URL 很麻烦的时候,就用  ASIHttpFormDataRequest

posted on 2012-05-16 13:27  猫叔jack  阅读(82)  评论(0编辑  收藏  举报