As the title says, unless the target is https, my get request returns nothing. I dont see any errors in order to troubleshoot. Is there something in the manifest I need to enable http for security purposes?
Asked
Active
Viewed 58 times
1
-
Is there something like parts of your code that we can see? – coderpc Apr 15 '19 at 20:20
-
Are you using an Android 9.0 (Pie) device or higher by chance? – PGMacDesign Apr 15 '19 at 20:28
-
Yes, I was wondering if it might be something in my options? And not necessarily something wrong with the code? I know it would be helpful to include my code, I thought I did because I posted the question and rushed out the door. I can post it when I get back – Jay Apr 15 '19 at 20:31
2 Answers
1
If you are running your app on a device / Emulator that is running Android Pie (9.0) or higher and are seeing this issue, it likely has to do with CleartextTraffic being set to false as the OS does this by default on this API level or higher.
See this SO answer here regarding why that is an issue and how to solve it.
If you just want to run it in testing and make sure the call works, add this code to your manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
And it should work. Be warned though that I have had apps rejected from the play store if I leave this in on release code.

PGMacDesign
- 6,092
- 8
- 41
- 78
0
To get errors in volley you need to implement the volley error listener eg
StringRequest request = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("response", response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return parameters;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
......
return headers;
}
};
RequestQueue queue = Volley.newRequestQueue(Class.this);
queue.add(request);
}

phang
- 518
- 4
- 20
-
I've included that, sorry I can include my code when I get home, is there a reason http wouldn't work? – Jay Apr 15 '19 at 20:11