我有一个使服务器发出GET请求的函数。它工作正常,但由于某种原因,它被称为两次。我按下按钮时调用函数。iOS HTTP请求被调用两次
这是功能代码:
-(void) GETasync: (NSString *) path{
receivedData = [[NSMutableData alloc] init];
NSURLRequest *request=[NSURLRequest requestWithURL:
[NSURL URLWithString: path]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60.0];
NSHTTPURLResponse * response;
NSError * error;
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"data received");
}
所以我在输出中看到:
2012-03-07 16:36:41.509 KW2[24136:bf03] data received
2012-03-07 16:36:41.694 KW2[24136:bf03] data received
我也有POST请求的功能,它是同样的麻烦吧。
您可以在显示代码的地方打电话给这个方法吗? – 2012-03-07 11:55:26
你是如何将按钮连接到该方法的? – 2012-03-07 11:57:16
该问题与连接POST无关。你按钮事件被称为一次以上。你如何分配按钮上的事件? – 2012-03-07 11:57:16