DELETE android with Webservice URL does not work

Asked

Viewed 63 times

1

I’m with an annoying problem that I haven’t been able to solve yet and involves PHP and Android (more PHP actually).

I’m accessing a PHP Webservice that makes an operation according to each method requested by Android (for example: POST makes Insert, PUT update, etc.), all methods POST, PUT e GET are working quiet, but the DELETE nay.

I will show the snippet of the code in PHP and try to explain:

else if ($metodoHttp == 'DELETE') {
    $stmt = $conn->prepare("DELETE FROM hotel_db.Hotel WHERE id=?");
    $segments = explode("/", $_SERVER["REQUEST_URI"]);
    $id = $segments[count($segments)-1];
    $stmt->bind_param("i", $id);
    $stmt->execute();
    $stmt->close();
    $jsonRetorno = array("id"=>$id);
    echo json_encode($jsonRetorno);
}

In this code, the PHP page checks if the method is the DELETE and if it is, it takes the parameter that comes with the URL after the / deletes the record in the database with this id, and returns the deleted record id.

On android asked to write in Log the URL that was being sent to see if it was going right and it is going like this:

http://meusite.com/bruno/Exemplos/Post/webservice.php/11

I do not know if there is an error in the PHP code (in the way it recovers the id in the URL) because on android seems to be all right.

  • I was able to solve the problem in webservice php on the line:<p><code>$Segments = explode("/", $_SERVER["REQUEST_URI"]);</code><p> The method <code>$_SERVER["REQUEST_URI"]</code> does not work on my server so I switched to <code>$_SERVER["ORIG_PATH_INFO"]</code> and it worked.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.