JSON POST を受け取り、http ステータス コードを返す基本的な php スクリプト コードがあります。
PHPはJSONを正常に受信し、http 200ステータスコードを送信しますが、どういうわけかAFNetworkingは取得Expected status code in (200-299), got 500
します.phpスクリプトで500ステータスコードを定義しますが、そのステータスコードを使用/送信することはありません.phpスクリプトを何度も何度も探しています.正しいコードを送信します200
が、 AFNetworking はそれを次のように受け取ります。500
PHP:
//send delete request here
$query ="DELETE FROM OWN_EVENTS WHERE event_id IN ('$names')";
$result = $sql->query($query);
//printf("$query: %s\n", $query);
//var_dump($query);
//printf("\n");
if (!$result) {
//var_dump($result);
//printf("\n");
//printf("Query failed: %s\n", $mysqli->error);
sendResponse(417, json_encode("Query failed"));
exit;
}
sendResponse(200, json_encode("Event Deleted"));
IOS
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>
エラーでわかるようにNSLocalizedRecoverySuggestion="Event Deleted"
、phpが実際に送信すると言っています200
私は何を間違っていますか?