【发布时间】:2015-04-05 12:53:13
【问题描述】:
我在目标 C 中使用 AFNetworking 删除照片时遇到问题。 这是我的目标 c 代码:
- (void)supprimerPhoto:(NSString*)nomPhoto{
NSString *stringUrl =URL_DELETE_PHOTO;
//NSURL *filePath = [NSURL URLWithString:[[URL_PHOTOS stringByAppendingString:nomPhoto]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSDictionary *parameters = @{@"photo_a_supprimer" : nomPhoto};
[manager POST:stringUrl parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"OK");
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error=%@", error.description);
NSLog(@"responseString=%@", operation.responseString);
}];
}
这是我的 php:
<?php
error_reportin(E_ALL);
header('Content-type: application/json')
$photo_a_supprimer=$_POST["photo_a_supprimer"];
if (file_exists("Photos/".$photo_a_supprimer))
{
unlink("Photos/".$photo_a_supprimer); // ok c’est supprimé
}
?>
当它执行时我有这个错误:
2015-04-05 17:19:07.357 TableauDeChasse[4607:4457365] error=Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo=0x792b9460 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7869db00> { URL: http://tableaudechasse.fr/DeletePhoto.php } { status code: 500, headers {
Connection = close;
"Content-Encoding" = gzip;
"Content-Type" = "text/html";
Date = "Sun, 05 Apr 2015 15:19:03 GMT";
Server = Apache;
"Set-Cookie" = "300gp=R393523723; path=/; expires=Sun, 05-Apr-2015 16:26:57 GMT";
"Transfer-Encoding" = Identity;
Vary = "Accept-Encoding";
"X-Powered-By" = "PHP/5.4.38";
} }, NSErrorFailingURLKey=http://tableaudechasse.fr/DeletePhoto.php, NSLocalizedDescription=Request failed: internal server error (500), com.alamofire.serialization.response.error.data=<>}
2015-04-05 17:19:10.679 TableauDeChasse[4607:4457365] responseString=
有人能解释一下我的连接出了什么问题吗? 似乎问题来自 .php 但如果您有建议会很好。
【问题讨论】:
-
将错误级别设置为 E_ALL,display_errors 设置为 true,并记录服务器响应,它可能会为您提供足够的信息来调试问题。
-
是的 Rob,我只想发送要删除的文件的名称。我怎样才能以简单的方式使用 Post?也许我可以在没有 AFNetworking 的情况下做到这一点?
-
顺便说一句,PHP 代码中似乎有一个额外的
unlink。我怀疑您在试验服务器代码时已经完成了,但这是不正确的。在检查文件是否存在之前删除您所做的unlink。
标签: php ios objective-c afnetworking