Reputation: 1
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("Accept", "application/json");
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(data.toString());
wr.flush();
status = con.getResponseCode();
This code is part of an AsyncTask class in Android Studio. When I execute a Post request using PostMan, the status returned is 200; however, when I make the request using the android emulator, the status is returned as 0. I'm super confused, and some help would be appreciated.
Upvotes: 0
Views: 691
Reputation: 2688
Status code 0 means some kind of network error. Try checking for:
Upvotes: 0