Advertisement
abouttr3

HTTPPost

Jul 6th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. private static String receiveFromBackEnd(String url, String json) throws IOException, JSONException {
  2.         StringBuilder str = new StringBuilder();
  3.  
  4.         HttpClient httpclient = new DefaultHttpClient();
  5.         HttpPost httppost = new HttpPost(url);
  6.         httppost.addHeader(new BasicHeader("Content-Type",
  7.                 "application/json"));
  8.  
  9.         httppost.setEntity(new StringEntity(json));
  10.  
  11.         HttpResponse response = httpclient.execute(httppost);
  12.  
  13.         BufferedReader reader = new BufferedReader(new InputStreamReader(
  14.                 response.getEntity().getContent()));
  15.         String line;
  16.         while ((line = reader.readLine()) != null) {
  17.             str.append(line);
  18.         }
  19.  
  20.         return str.toString();
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement