Android Volley ignoring params can't connect

AND4011002849

I'm trying to connect to a local API using volley, I passed all the required parameters but it's not working, if I get rid of the email and password and let only the token request it works, so the problem is in the email and password, but those parameters are being ignored, how can I get it working?

package quest.testvolley;

import com.android.volley.AuthFailureError;
import com.android.volley.VolleyLog;
import com.kpbird.volleytest.R;



        import org.json.JSONObject;

        import android.app.Activity;
        import android.os.Bundle;
        import android.view.Menu;
        import android.view.View;
        import android.widget.TextView;

        import com.android.volley.Request;
        import com.android.volley.RequestQueue;
        import com.android.volley.Response;
        import com.android.volley.VolleyError;
        import com.android.volley.toolbox.JsonObjectRequest;
        import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends Activity {

    private TextView txtDisplay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txtDisplay = (TextView) findViewById(R.id.txtDisplay);

        RequestQueue queue = Volley.newRequestQueue(this);


        String url = "http://192.168.1.1/represente-mais-api/api/clientes";

        HashMap<String, String> params = new HashMap<String, String>();
        params.put("email", "[email protected]");
        params.put("senha", "sss");
        //params.put("X-API-TOKEN", "99KI9Gj68CgCf70deM22Ka64chef2C40Gm2lFJ2J0G9JkD0afd19MfacGa3FFm8CM1hG0eDiIk8");




        JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET,
                url, new JSONObject(params),
                new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {

                txtDisplay.setText("Response => "+response.toString());
                findViewById(R.id.progressBar1).setVisibility(View.GONE);
            }
        }, new Response.ErrorListener() {



                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d( "Error: " + error.getMessage());


                }
            })



        {

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    HashMap<String, String> headers = new HashMap<String, String>();


                    headers.put("X-API-TOKEN", "99KI9Gj68CgCf70deM22Ka64chef2C40Gm2lFJ2J0G9JkD0bDAcbFfd19MfacGf3FFm8CM1hG0eDiIk8");

                    return headers;
                }



        };
        queue.add(req);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
Robin Eisenberg

You are specifying the HTTP Request type as GET, yet adding form data to it.

    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, ...

You want to be doing an HTTP Post method. Therefore you should replace Request.Method.GET to Request.Method.POST to post FormData to the server.

More about HTTP Methods here.

EDIT: If you are getting a 401 while trying an HTACCESS see this question. You need to pass the parameters using an Authenticator.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

posting params as json in android volley

From Dev

how to send array of params using volley in android

From Dev

Android - Volley fails to send my Params to the server

From Dev

Unable to pass Params through Volley Request in android

From Dev

android bluetooth can't connect

From Dev

android bluetooth can't connect

From Dev

Android app can't connect to hostname but can connect to IP on server

From Dev

Can't change layout params of Nestedscrollview Dynamically (android)

From Dev

Android Volley doesn't seem to be able to connect to Flask localhost address for GET method for return String from Flask?

From Dev

How can I test for calls ignoring params arguments in NSubstitute?

From Dev

Android App Can't Connect to Server

From Dev

Can't connect to a node js server in Android

From Dev

android studio can't connect to debug devices

From Dev

Spika-Android: "Can't connect to server"

From Dev

Android Studio : Can't connect to mobile device

From Dev

Can't connect to a node js server in Android

From Dev

android studio can't connect to debug devices

From Dev

Can't connect Android devices to MacBook Pro

From Dev

Adding an array in params.put to volley request in android

From Dev

Recycler View Not Reading Big Volley data with params in android

From Dev

Android Volley - can't do a JSON request with POST, getting empty response

From Dev

Can't import the volley library in eclipse

From Dev

Eclipse + volley can't import the library

From Dev

Can't create by "XXX_params", though params are available

From Dev

Can't create by "XXX_params", though params are available

From Dev

apache - Can't connect to apache local server between ubuntu and android

From Dev

Android wearable emulator can't connect with usb connected phone

From Dev

Android Wear can't connect my device via bluetooth

From Dev

Why can't Android Wear connect target for debugging over Bluetooth?

Related Related

  1. 1

    posting params as json in android volley

  2. 2

    how to send array of params using volley in android

  3. 3

    Android - Volley fails to send my Params to the server

  4. 4

    Unable to pass Params through Volley Request in android

  5. 5

    android bluetooth can't connect

  6. 6

    android bluetooth can't connect

  7. 7

    Android app can't connect to hostname but can connect to IP on server

  8. 8

    Can't change layout params of Nestedscrollview Dynamically (android)

  9. 9

    Android Volley doesn't seem to be able to connect to Flask localhost address for GET method for return String from Flask?

  10. 10

    How can I test for calls ignoring params arguments in NSubstitute?

  11. 11

    Android App Can't Connect to Server

  12. 12

    Can't connect to a node js server in Android

  13. 13

    android studio can't connect to debug devices

  14. 14

    Spika-Android: "Can't connect to server"

  15. 15

    Android Studio : Can't connect to mobile device

  16. 16

    Can't connect to a node js server in Android

  17. 17

    android studio can't connect to debug devices

  18. 18

    Can't connect Android devices to MacBook Pro

  19. 19

    Adding an array in params.put to volley request in android

  20. 20

    Recycler View Not Reading Big Volley data with params in android

  21. 21

    Android Volley - can't do a JSON request with POST, getting empty response

  22. 22

    Can't import the volley library in eclipse

  23. 23

    Eclipse + volley can't import the library

  24. 24

    Can't create by "XXX_params", though params are available

  25. 25

    Can't create by "XXX_params", though params are available

  26. 26

    apache - Can't connect to apache local server between ubuntu and android

  27. 27

    Android wearable emulator can't connect with usb connected phone

  28. 28

    Android Wear can't connect my device via bluetooth

  29. 29

    Why can't Android Wear connect target for debugging over Bluetooth?

HotTag

Archive