Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. private static String receiveFromHttpBackEnd(String url, String json) throws IOException, JSONException {
  2.         URL obj = new URL(url);
  3.         HttpURLConnection con = (HttpURLConnection) obj.openConnection();
  4.  
  5.         String USER_AGENT = "Mozilla/5.0";
  6.         //add reuqest header
  7.         con.setRequestMethod("POST");
  8.         con.setRequestProperty("User-Agent", USER_AGENT);
  9.         con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  10.         con.setRequestProperty("Content-Type", "application/json");
  11.  
  12.         // Send post request
  13.         con.setDoOutput(true);
  14.         DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  15.         wr.writeBytes(json);
  16.         wr.flush();
  17.         wr.close();
  18.  
  19.         return getResponse(con.getInputStream());
  20.     }