Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AFNetworking正在接收尚未由服务器发送的状态代码_Php_Ios_Objective C_Afnetworking - Fatal编程技术网

Php AFNetworking正在接收尚未由服务器发送的状态代码

Php AFNetworking正在接收尚未由服务器发送的状态代码,php,ios,objective-c,afnetworking,Php,Ios,Objective C,Afnetworking,我有一个基本的php脚本代码,它接收JSON POST并发回http状态代码 PHP成功接收JSON并发送http 200状态代码,但在(200-299)中获得预期状态代码,获得500,在PHP脚本中我定义了500个状态代码,但我从未使用/发送该状态代码,我一直在一遍又一遍地寻找php脚本,没有它发送正确的代码200,但是AFNetworking接收到它的代码是500 PHP: IOS 错误: Error: Error Domain=AFNetworkingErrorDomain Code=-1

我有一个基本的php脚本代码,它接收JSON POST并发回http状态代码

PHP成功接收JSON并发送http 200状态代码,但在(200-299)中获得
预期状态代码,获得500
,在PHP脚本中我定义了500个状态代码,但我从未使用/发送该状态代码,我一直在一遍又一遍地寻找php脚本,没有它发送正确的代码
200
,但是AFNetworking接收到它的代码是
500

PHP:

IOS

错误:

Error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 500" UserInfo=0x11c8c9d0 {NSLocalizedRecoverySuggestion="Event Deleted", AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest http://host.php>, NSErrorFailingURLKey=http://host.php, NSLocalizedDescription=Expected status code in (200-299), got 500, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xa9aba80>
Error:Error Domain=AFNetworkingErrorDomain code=-1011“预期状态代码在(200-299)中,获得500”UserInfo=0x11c8c9d0{nsLocalizedRecoverysSuggestion=“事件已删除”,AFNetworkingOperationFailingURLRequestErrorKey=,NSErrorFailingURLKey==http://host.php,NSLocalizedDescription=中的预期状态代码(200-299),获得500,AFNetworkingOperationFailingURLResponseErrorKey=
正如您在错误中看到的,它说的是
nsLocalizedRecoverysSuggestion=“Event Deleted”
,因此php确实发送了
200


我做错了什么?

500是内部服务器错误的HTTP状态代码。问题完全在于您的php脚本如何响应请求。

php/服务器日志中是否有关于响应的任何内容?另外,您是否能够在浏览器中测试请求?我在中找不到
sendResponse
。我有用curl测试它,它返回“Event Deleted”
curl-v-H“Accept:application/json”-H“Content type:application/json”-X POST-d'{“Event_id”:[“420”]}'  http://host.php
-v
还应显示响应标题。我假设您将返回
作为第一个响应行。您可以共享完整的curl输出吗?然后尝试更正我的php脚本,并在有响应行时发布我的解决方案
NSError* error;
    NSMutableDictionary *nameElements = [[NSMutableDictionary alloc] init];
    [nameElements setObject:saveArray forKey:@"event_id"];

    NSData *result =[NSJSONSerialization dataWithJSONObject:nameElements options:0 error:&error];
    NSString *displayJson = [[NSString alloc] initWithData:result
                                                  encoding:NSUTF8StringEncoding];
    NSLog(@"saveArray result %@",displayJson);

    NSURL *url = [NSURL URLWithString:server];
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
    // don't forget to set parameterEncoding!
    httpClient.parameterEncoding = AFJSONParameterEncoding;
    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:deleteEventInDatabase parameters:nil];
    [request setHTTPBody:[displayJson  dataUsingEncoding:NSUTF8StringEncoding]];
    [request addValue:@"ASIHTTPRequest" forHTTPHeaderField:@"User-Agent"];
    [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    NSLog(@"request %@",request);
    [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:nil failure:nil];
    operation.JSONReadingOptions = NSJSONReadingAllowFragments;
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id response) {
        // Print the response body in text
        if (operation.response.statusCode == 200) {
            NSLog(@"Events Sucessfully Deleted");

        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
        if (operation.response.statusCode == 500) {
            NSLog(@"Internal Server Error");
            //remove this when u fix it

        }
 }];

    [operation start];
Error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 500" UserInfo=0x11c8c9d0 {NSLocalizedRecoverySuggestion="Event Deleted", AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest http://host.php>, NSErrorFailingURLKey=http://host.php, NSLocalizedDescription=Expected status code in (200-299), got 500, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xa9aba80>