1
Sending the request the server behaves like it should not from the error, but from the Response side it generates the following error "com.android.Volley.volleyerror java.lang.runtimeException: bad url." I’m using Android studio , Webview and Volley.
Mainactivity class;
Map<String, String> postParam= new HashMap<>();
postParam.put("username", "admin");
postParam.put("password", "onblox");
CustonRequest jsObjRequest = new CustonRequest(
Request.Method.POST,
"http//:192.168.0.13:8088/onblox/login",
postParam,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(MainActivity.this,response.toString(),Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show();
}
});
rq.add(jsObjRequest);
Custonrequest class :
public class CustonRequest extends Request<JSONObject> {
private Response.Listener<JSONObject> response;
private Map<String,String> parm;
public CustonRequest(int method, String url, Map<String,String> parm, Response.Listener<JSONObject> response, Response.ErrorListener listener) {
super(method, url, listener);
this.response = response;
this.parm = parm;
}
public CustonRequest( String url, Map<String,String> parm, Response.Listener<JSONObject> response, Response.ErrorListener listener) {
super(Method.GET, url, listener);
this.response = response;
this.parm = parm;
}
public Map<String,String> getParm()throws AuthFailureError{
return parm;
}
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
String js = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
return (Response.success(new JSONObject(js),HttpHeaderParser.parseCacheHeaders(response)));
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}catch (JSONException e){
e.printStackTrace();
}
return null;
}
@Override
protected void deliverResponse(JSONObject response) {
this.response.onResponse(response);
}
}
After a search I changed the code a little I will update the question . The body of the answer comes empty , but the headers do not; I have to pick up the Authorization that comes into it, the server running it receives the request does the database search and returns me right more when it arrives in the App that I am creating from the error of com.android.Volleyerror java.lang.runtimeException: bad url.
– Aderbal
Probably your emulator is not able to locate your server on the localhost, to make sure, access a url on google Chrome by the emulator that does a get of something, in case the result does not come out we find the problem, then search for how to access the localhost server (regarding the respective server you are ultlizing) coming from your emulator
– WiseTap
Had already tested with a GET on the same server where we have a Controller that returns true , where this Controller only serves to check the connection and worked. I’m thinking that might be how Volley gets that answer. And TB is not the emulator I’m testing on a smartphone .
– Aderbal
Are you sure your phone is able to communicate with the server?
– WiseTap
By the Get method it returns a boolean yes.
– Aderbal
So I can’t help, buddy, good luck
– WiseTap
Thanks bro at least you tried that already counts for a lot.
– Aderbal