Open jfernandojr opened 8 years ago
Same kind of issue facing on a simple StringRequest. Weird Problem.
@jfernandojr can you test by setting HEADERS in the following way
@Override public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> params = new HashMap<>(); params.put("Content-Type", "application/x-www-form-urlencoded"); return params; }
or you need to Override the "getBodyContentType()" as you're using JSON request
@JChudasama I messed up on DevicesUserRequest () method. The correct code is as follows:
public class DevicesUserRequest extends JsonArrayRequest {
private static final String Protocol = "http://";
private static final String Host = "192.241.251.229";
private static final String Port = "8080";
private static final String FullHost = Protocol + Host + ":" + Port;
// private static final String sUrl = "http://gogps.com.br/gogps-rest/api/device/getDeviceUser";
private static final String sUrl = FullHost + "/Webservice/api/device/getLastInfDevice";
public DevicesUserRequest(JSONObject object, Response.Listener<JSONArray> listener,
Response.ErrorListener errorListener) {
super(sUrl, object, listener, errorListener);
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
return headers;
}
}
Notice that the only change was in the last url. Now I got the following error:
BasicNetwork.performRequest: Unexpected response code 401 for http://192.241.251.229:8080/Webservice/api/device/getLastInfDevice 02-15 20:35:18.754 11064-11064/? E/br.com.viprastreamento.rastreamento.ListaVeiculos: Look mistake here! com.android.volley.AuthFailureError at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:171) at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)
You need to authorise the request you're sending. Put your login credentials in Header Params.
You can also check on REST client 1st too.
I left my head as follows:
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
headers.put("imei", "459710040904196");
headers.put("acao", "pos");
return headers;
}
But the problem still remains.
Try something like this way
`@Override public Map<String, String> getHeaders() throws AuthFailureError { Map<String,String> headers = Constants.getHeaders(context); // add headers <key,value> String credentials = USERNAME+":"+PASSWORD; String auth = "Basic "
thus does not satisfy me. I have a method that makes login and password to the server. This method returns me a key that was called IMEI.
So nessse process I want to do, I have to connect through the imai and the command as a parameter, being as follows:
.put("imei", "459710040904196");
.put("acao", "pos");
I managed to implement a class in eclipse using the same parameters and functioned normally.
But in Android Studio, I'm having trouble.
I'm having trouble compiling the method below
It is showing the following error: com.android.volley.ParseError: org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONArray
Below is the class DevicesUserRequest: