I answered some time ago a case similar to yours, raised in this question: Problem receiving data on Android with JSON, PHP and MySQL
Since there the OP seems to have abandoned the question, I almost put that answer here, because it explains the source of the problem by citing the source, then giving some solutions.
The origin of the problem
In the case you raise, the URLs are being encoded according to the RFC 3986
, which explains in section 2.1 that URLs containing non-allowed characters will be replaced by the% sign %
followed by its binary octet . The section puts just as an example the blank, whose binary octet would be 20
, so a URL containing blank spaces, these spaces are replaced by %20
.
Therefore, in requests whose URL is created like this in your application:
http://sapito.org/Archivos/File/registrys2.php?frase=La casa de martin es roja
If RFC 3986
is applied, the server will receive the URL like this:
http://sapito.org/Archivos/File/registrys2.php?frase=La%20casa%20de%20martin%20es%20roja
Solutions
Several solutions are possible, either on the application side or on the server side.
A. On the application side
You can replace blank spaces by the +
sign, doing something like this:
String frase="La casa de martin es roja";
frase = frase.replaceAll(" ", "+");
This will produce a URL like that, which is totally valid for the case at hand:
http://sapito.org/Archivos/File/registrys2.php?frase=La+casa+de+martin+es+roja
B. On the server side
You can let the application send the encoded URL according to the RFC 3986
rule and work it on the server.
$urlPost=( empty($_GET["frase"]) ) ? NULL : urldecode($_GET["frase"]);
if ($urlPost){
//Trabajar con la URL
}else{
//Indicar el error en forma de array
}
//Emitir la respuesta
You can also make a replacement instead of using urldecode
. But, it is not worth giving up a function that exists precisely for that. Note that on the application side it would not make any sense to decode the URL, because it is encoded precisely when it is sent to the server.