I am making a post request to this endpoint http://httpbin.org/post
which should return the post I make, which would be String data = "something to post";
but I don't know if the post request has been successful. How can I find out?
Here the code I am using:
public class Post extends AsyncTask <String, String, String>{
@Override
protected String doInBackground(String... strings) {
String urlString = "http://httpbin.org/post"; // URL to call
Log.d("Blyat", urlString);
String data = "something to post"; //data to post
OutputStream out = null;
try {
URL url = new URL(urlString);
Log.d("Post", String.valueOf(url));
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
out = new BufferedOutputStream(urlConnection.getOutputStream());
Log.d("Post", String.valueOf(out));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
writer.write(data);
writer.flush();
writer.close();
out.close();
urlConnection.connect();
Log.d("Post", String.valueOf(urlConnection));
} catch (Exception e) {
System.out.println(e.getMessage());
}
String algo = "blure";
return algo;
}
}