Cannot send complete string in Android Studio:
json_sales = "Client: blabla & net...."
HttpRequest req = null;
JSONArray products = null;
JSONObject json = null;
json_sales = json_sales.replace("
", " ");
HashMap<String, String> params = new HashMap<>();
params.put("data", json_sales);
params.put("tipo", "vd");
String l_resp = "";
try {
req = new HttpRequest(server + "/importallsalses.php");
l_resp = req.prepare(HttpRequest.Method.POST).withData(params).sendAndReadString();
} ...
file: importallsalses.php
<?php
error_reporting(0);
include "adodb5/adodb.inc.php";
$data=$_POST["data"];
$tipo=$_POST["tipo"];
echo $data;
?>
Result - echo: "Client: blabla"
My problem is ampersand. How can I resolve this?
It looks like you are not encoding the ampersand &
symbol before sending it.
Using Javas URLEncoder
is likely your friend here. Changing your params.put()
assignment to the below should solve it:
params.put("data", URLEncoder.encode(json_sales, "utf-8"));