Fórum

android Jsonws URL

nicolas Roman Buitrago, modificado 7 Anos atrás.

android Jsonws URL

New Member Postagens: 3 Data de Entrada: 16/03/16 Postagens Recentes
Hi!

I'm trying to access json services in android through the library volley, like this:


final static String JSON_URL = "http://192.168.0.2:8080/api/jsonws/user/get-user-by-id/user-id/21836";
JsonObjectRequest jsObjRequest = new JsonObjectRequest
                        (Request.Method.GET,JSON_URL , null, new Response.Listener<jsonobject>() {

                            @Override
                            public void onResponse(JSONObject response) {
                                mTextView.setText("Response: " + response.toString());
                            }
                        }, new Response.ErrorListener() {

                            @Override
                            public void onErrorResponse(VolleyError error) {
                                mTextView.setText("That didn't work!");
                                mTextView.setText(error.toString());

                            }
                        });
</jsonobject>


And the result I get is:
{"message":"Authenticated access required","exception":"java.lang.SecurityException"}

I read about passing user credentials in the URL. "http://test&40liferay.com:test@192.168.0.2:8080/api/jsonws/user/get-user-by-id/user-id/21836"
but got the same result.

I also used the BasicAthentication of mobile SDK and LoginScreenlet of liferayScreens, obtaining the same.

how I can get the JSON result through the URL?
Thanks!
thumbnail
Javier Gamarra, modificado 7 Anos atrás.

RE: android Jsonws URL

Expert Postagens: 348 Data de Entrada: 12/02/15 Postagens Recentes
Have you tried adding a Basic Authentication Header like this?

The error basically says that the request is missing the auth header, it should work fine with the Mobile SDK though.

Can you try the link, if it fails I can do a quick check with volley...
nicolas Roman Buitrago, modificado 7 Anos atrás.

RE: android Jsonws URL

New Member Postagens: 3 Data de Entrada: 16/03/16 Postagens Recentes
It worked adding a Header.
Thank you very much!