Ciao a tutti, come da titolo della discussione, sto provando ormai non so neanche più da quanto, ad inviare un JSON ad un Server utilizzando la libreria Volley per Android.
Dopo tantissime ricerche su internet, se non ho capito male, credo di avere trovato finalmente il modo giusto per inviare questo JSON.
Vi posto il codice:
codice:
public void sendJson() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("ID", "1234");
} catch (JSONException e) {
e.printStackTrace();
}
RequestQueue queue = Volley.newRequestQueue(this);
JsonObjectRequest jsObjRequest = new JsonObjectRequest(
Request.Method.POST, URL,
jsonObject,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "Response: " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error: " +error.getMessage());
}
});
queue.add(jsObjRequest);
}
La risposta che però ricevo dal server è:
codice:
11-22 10:59:42.220 5657-5657/com.example.utente.jsonrequesttest D/MainActivity: Error: org.json.JSONException: End of input at character 0 of
Sapete dirmi cosa sto sbagliando?
Come al solito, vi ringrazio anticipatamente per la vostra disponibilità.