首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

求教关于HTTP异步请求的有关问题?了!

2012-12-16 
求教关于HTTP异步请求的问题?请教各位了!!!!!!!!!!!!!新建一个single View Application的工程,再建一个类,

求教关于HTTP异步请求的问题?请教各位了!!!!!!!!!!!!!
新建一个single View Application的工程,再建一个类,专门用来实现HTTP请求数据的功能
如下,只写了一个函数实现异步调用
-(void) postDataInfo:(NSString*) nsPostVar:(NSString*)nsUrl:(NSString*)nsReferer
{
    NSData *postData = [nsPostVar dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];  
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];  
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];  
    [request setURL:[NSURL URLWithString:nsUrl]];  
    
    [request setHTTPMethod:@"POST"]; 
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];  
    [request setValue:nsReferer forHTTPHeaderField:@"Referer"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];  
    [request setHTTPBody:postData];  
    
    
   
    self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate     App].viewController];  //异步处理,委托主View接受信息
    
    
}
主view中
//全部数据接收完毕时触发
- (void)connectionDidFinishLoading:(NSURLConnection *)aConn
{
    NSLog(@"connectionDidFinishLoading");
}

另外新建了一个view,专门来显示数据
在这个viewController中,我新建了2个timer来调用 postDataInfo
如下
- (void)postWonMoney
{
    [[AppDelegate App].viewController.pwebOperator postDataInfo:参数1:参数2:参数3];
  
}
/////////////////view显示的时候就执行这个timer
[NSTimer scheduledTimerWithTimeInterval:(1) target:self selector:@selector(responseInfoTimer) userInfo:nil repeats:YES];
- (void)responseInfoTimer{
  [self postWonMoney];//此处调用可以成功,能得到HTTP请求的数据
  //如果此处再设定一个定时器,如下
  [NSTimer scheduledTimerWithTimeInterval:(5) target:self selector:@selector(responseInfoTimer2) userInfo:nil repeats:YES];
}
- (void)responseInfoTimer2{
  [self postWonMoney];//此处调用不成功,能得到HTTP请求的数据
  //程序执行完self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate     App].viewController]; 就崩溃了
}
请问这是什么原因,为什么在第一个定时器那里执行是没有问题的呢
[最优解释]
崩溃后,命令行给出的提示信息是什么?

[其他解释]
自己先顶一下先
[其他解释]
不会吧,没有人知道啊
[其他解释]
没有人知道吗
[其他解释]

引用:
崩溃后,命令行给出的提示信息是什么?

崩溃后程序调到这里
@autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
后面提示Thread 1:EXC_BREAKPOINT(code=EXC_I386_BPT,subcode=0x0)
命令行无任何提示
------其他解决方案--------------------


执行完
self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController];
在接收的函数
//全部数据接收完毕时触发
- (void)connectionDidFinishLoading:(NSURLConnection *)aConn
{
  NSLog(@"connectionDidFinishLoading");
}没有执行的时候就报错了,是不是委托那里有问题,在TIMER里面再建立一个TIMER,然后第二个TIMER的执行函数里面去调用就会出问题,如果只是一个TIMER,然后在这个TIMER的执行函数里面去调用是没有问题的
[其他解释]

引用:
崩溃后,命令行给出的提示信息是什么?

执行完
self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController];
在接收的函数
//全部数据接收完毕时触发
- (void)connectionDidFinishLoading:(NSURLConnection *)aConn
{
  NSLog(@"connectionDidFinishLoading");
}没有执行的时候就报错了,是不是委托那里有问题,在TIMER里面再建立一个TIMER,然后第二个TIMER的执行函数里面去调用就会出问题,如果只是一个TIMER,然后在这个TIMER的执行函数里面去调用是没有问题的
[其他解释]
让奔溃信息给的更全些,参考这个:http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode

[其他解释]
可能是过度释放引起的。
需要输出更多的调试信息,参考:
http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode
http://stackoverflow.com/questions/2190227/how-do-i-set-up-nszombieenabled-in-xcode-4
http://blog.csdn.net/linzhiji/article/details/6771998
[其他解释]
引用:
可能是过度释放引起的。
需要输出更多的调试信息,参考:
http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode
http://stackoverflow.com/questions/2190227/how-do-i-set-up-nszombieenabled-in-xcode-4
http:/……
命令行给出的提示是这个
-[CFRunLoopTimer release]: message sent to deallocated instance 0x162ac330

[其他解释]
用asihttp啦
[其他解释]
那问题已经清楚了。就是释放了,已经被释放的对象,俗称“僵尸对象”。看看那几个 Timer 的申请与释放。
[其他解释]
 self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController]; //异步处理,委托主View接受信息

这个每次赋值的时候会把前面一个Info release,而前面那个info的请求还在执行,就会出问题。
建议赋值前先self.info调用一下cancel。
[其他解释]
引用:
那问题已经清楚了。就是释放了,已经被释放的对象,俗称“僵尸对象”。看看那几个 Timer 的申请与释放。

恩,对的,我按照前辈的提示,查看到CFRunLoopTimer release的错误 ,就去找TIMER的问题,果然是这里的问题,第二个TIMER赋值的时候一定要self.第二个TIMER的对象=XXXX,这样就没有问题了
前辈能否再帮我看看这个显示的问题,多谢了,晚上来接贴
http://www.cocoachina.com/bbs/read.php?tid=112855&page=1#670884

热点排行