ASIHTTPRequest 给我带来了问题
我有一个将 POST 数据发送到 PHP 网站的代码。代码:
request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://www.example.com/Testing/Testing.php"]];
[request setPostValue:targettype forKey:@"targettype"];
[request setPostValue:targetmethod forKey:@"targetmethod"];
[request setPostValue:sourceurl forKey:@"sourceurl"];
[request setPostValue:filepath forKey:@"filepath"];
[request setDelegate:self];
[request startAsynchronous];
这工作正常。发送此数据并且 PHP 脚本输出一些数据后,该脚本将创建一个 .txt 文件。一旦 iPhone 读取 .txt 文件的内容,我想对另一个 PHP 脚本运行 ASIHTTPRequest,该脚本应该删除该 .txt 文件。从 PHP 端来看,一切似乎都正常,并且 iPhone 完美地接收了数据。但是,一旦收到数据,我就会有一个 if...then 语句来检查数据,然后一旦数据存在,我想调用 ASIHTTPRequest 来删除 .txt。这是我用来将数据 POST 到新 PHP 位置的代码:
{...
imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString: string]]];
[self deletefile];
}
-(void) deletefile {
request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://www.prajoth.com/Testing/Testing.php"]];
[request setPostValue:@"hey" forKey:@"targettype"];
[request setPostValue:@"hey" forKey:@"targetmethod"];
[request setPostValue:@"hey" forKey:@"sourceurl"];
[request setPostValue:filepath forKey:@"filepath"];
[request setDelegate:self];
[request startAsynchronous];
}
由于某种原因,抛出了 EXC_BAD_ACCESS。但控制台没有显示任何错误消息。请帮忙!
I have a code that sends POST data to a PHP website. Code:
request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://www.example.com/Testing/Testing.php"]];
[request setPostValue:targettype forKey:@"targettype"];
[request setPostValue:targetmethod forKey:@"targetmethod"];
[request setPostValue:sourceurl forKey:@"sourceurl"];
[request setPostValue:filepath forKey:@"filepath"];
[request setDelegate:self];
[request startAsynchronous];
This is working perfectly. Once this data is sent and the PHP script outputs some data, the script creates a .txt file. Once the iPhone reads the contents of the .txt file, I want to run ASIHTTPRequest to a different PHP script that is supposed to delete this .txt file. From a PHP end, everything seems to be working, and the data is being received perfectly by the iPhone. However, once the data is received, I have a if...then statement that checks for the data and then once the data is present, I want to call ASIHTTPRequest to delete the .txt. This is the code I used to POST the data to the new PHP location:
{...
imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString: string]]];
[self deletefile];
}
-(void) deletefile {
request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://www.prajoth.com/Testing/Testing.php"]];
[request setPostValue:@"hey" forKey:@"targettype"];
[request setPostValue:@"hey" forKey:@"targetmethod"];
[request setPostValue:@"hey" forKey:@"sourceurl"];
[request setPostValue:filepath forKey:@"filepath"];
[request setDelegate:self];
[request startAsynchronous];
}
This is for some reason, throwing up a EXC_BAD_ACCESS. The console does not show any error message though. Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您粘贴的代码,很难弄清楚这一点。您的应用程序到底在哪里抛出异常?它可能是您的全局变量之一不再存在(例如,
filepath
),但它也可能是代码中其他地方的东西。正如您可能猜到的,EXC_BAD_ACCESS
消息是在您尝试访问不再位于内存中的对象时发生的,因此您可能正在释放您现在依赖的早期对象?Based on the code you've pasted, it's going to be difficult to figure this out. Where exactly is your app throwing the exception? It could be perhaps one of your global variables doesn't exist any more (
filepath
, for example), but then again it could also be something elsewhere in your code.EXC_BAD_ACCESS
messages, as you can probably guess, occur when you try to access an object that's no longer in memory, so maybe you are releasing something earlier on which you now rely on?