Hi have this error when I try to send accents from android to an php api:
Notice: Trying to get property of non-object in /storage/ssd1/452/8869452/myapi.php
I use postman to test my API and I sent accenst with It and all works, but when I try to sent accents from android I get the error.
$respuesta["mensaje"] = array();
$json=file_get_contents('php://input');
$obj=json_decode($json);
$idresp=filter_var($obj->idresp);`
My json object that I sent It is the next:
{
"QR":"76CD1L3hOb",
"idresp":"53",
"idportador":"4"
}
My android code it's the next
JSONObject jsonUpdate = new JSONObject();
try {
jsonUpdate.put("QR", QR);
jsonUpdate.put("idresp", idusuario);
jsonUpdate.put("idportador",txtidPortador.getText().toString().trim());
new AgregarPortador(dialogoRecuperarCuenta).execute("myURLofMyApi.php", jsonUpdate.toString());
} catch (JSONException e) {
Log.e("Error :c", "El error:
" + e);
}//Cierra catch
The asynchTask code:
@Override
protected String doInBackground(String... strings) {
String data = "";
HttpURLConnection httpURLConnection = null;
try {
httpURLConnection = (HttpURLConnection) new URL(strings[0]).openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(httpURLConnection.getOutputStream());
wr.writeBytes(strings[1]);
wr.flush();
wr.close();
InputStream in = httpURLConnection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(in);
int inputStreamData = inputStreamReader.read();
while (inputStreamData != -1) {
char current = (char) inputStreamData;
inputStreamData = inputStreamReader.read();
data += current;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
return data;
}