Estoy trabajando en una aplicación speech to text en android y uso la api de google y volley para ello, pero tengo un problema cuando intento enviar un json al servidor. Todo el rato recibo el error de http 400. He intentado resolver que pasa o que hago mal y después de dos semanas no he conseguido nada, aquí os dejo el código:
url = "https://netav3a.balidea.com/api/voice";
JSONObject jsonParam = new JSONObject();
try {
jsonParam.put("text", s);
jsonParam.put("language", "es-ES");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println(jsonParam.toString());
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
final String mensaje = s;
RequestQueue queue = Volley.newRequestQueue(Castellano.this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, jsonParam,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(Castellano.this, response.toString(), Toast.LENGTH_LONG).show();
System.out.println(response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Castellano.this, error.toString(), Toast.LENGTH_LONG).show();
System.out.println(error.toString());
NetworkResponse networkResponse = error.networkResponse;
if (networkResponse != null) {
Log.e("Volley", "Error. HTTP Status Code:" + networkResponse.statusCode);
}
if (error instanceof TimeoutError) {
Log.e("Volley", "TimeoutError");
} else if (error instanceof NoConnectionError) {
Log.e("Volley", "NoConnectionError");
} else if (error instanceof AuthFailureError) {
Log.e("Volley", "AuthFailureError");
} else if (error instanceof ServerError) {
Log.e("Volley", "ServerError");
} else if (error instanceof NetworkError) {
Log.e("Volley", "NetworkError");
} else if (error instanceof ParseError) {
Log.e("Volley", "ParseError");
}
}
})
{
@Override
public Map getHeaders() throws AuthFailureError {
HashMap headers = new HashMap();
headers.put("Content-Type", "application/json;");
headers.put("apiKey", "xxxxxxxxxxxxxxx");
return headers;
}
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("text", mensaje);
params.put("language", "es-ES");
return params;
}
};
queue.add(jsonObjectRequest);
y cada vez que ejecuto el programa me da como resultado esto
E/Volley: [198] BasicNetwork.performRequest: Unexpected response code 400 for (la url por motivos personales la omito)
I/System.out: com.android.volley.ClientError
E/Volley: Error. HTTP Status Code:400
E/Volley: ServerError
Me gustaria saber en que fallo y como arreglarlo, llevo ya mucho tiempo en esto solo y no soy capaz de arreglarlo.