Error (400) when connecting Android Studio with API

0

I'm trying to get an API get but it returns a 400, I've tried putting my local IP and putting 10.0.2.2 , but the same thing keeps coming up, in the Event Log I get this too: Emulator: CAN NOT TRANSLATE guest DNS ip , from the PostMan it returns the JSON correctly so I do not think it's a problem of that

This is where I do everything

public void PendingTrajects(){
   AsyncHttpClient client = new AsyncHttpClient();
   String URL = "http://ip:puerto/api/trajectes";
   client.get(this, URL, new AsyncHttpResponseHandler() {

       @Override
       public void onStart() {
           Toast.makeText(PendingTrajectRecyclerView.this, "Carregant...", Toast.LENGTH_SHORT).show();
       }

       @Override
       public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
           JSONArray Usuaris = new JSONArray();
           JSONArray trajectes = new JSONArray();

           String Nom = null;

           String strResponseBody = new String(responseBody);

           try {
               //Usuari = new JSONArray(strResponseBody);
               trajectes = new JSONArray(strResponseBody);
           }catch (JSONException e){
               Toast.makeText(PendingTrajectRecyclerView.this, "Error a la connexió", Toast.LENGTH_SHORT).show();
           }

           try {
               for(int i = 0; i < trajectes.length(); i++){
                   JSONObject trajecte = trajectes.getJSONObject(i);
                   JSONArray realitzas = trajecte.getJSONArray("realitzas");
                   for(int j = 0; j < realitzas.length(); j++){
                       JSONObject realitza = realitzas.getJSONObject(j);
                       JSONObject usuari = realitza.getJSONObject("usuari");
                       Log.d("xd", ""+usuari.getString("name"));
                   }
               }
           }catch (JSONException e){
               Toast.makeText(PendingTrajectRecyclerView.this, "Error a la connexió", Toast.LENGTH_SHORT).show();
           }
       }

       @Override
       public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, byte[] responseBody, Throwable error) {
           Toast.makeText(PendingTrajectRecyclerView.this, "Error a la connexió ONFailure", Toast.LENGTH_SHORT).show();
           Log.d("Fallo",""+statusCode);
       }

   });
    
asked by Lluís 11.05.2018 в 22:46
source

0 answers