You can use the following:
public static String executeHttpPost1(String url, HashMap<String, String> postParameters) throws UnsupportedEncodingException { // TODO Auto-generated method stub HttpClient client = getNewHttpClient(); try{ request = new HttpPost(url); } catch(Exception e){ e.printStackTrace(); } if(postParameters!=null && postParameters.isEmpty()==false){ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(postParameters.size()); String k, v; Iterator<String> itKeys = postParameters.keySet().iterator(); while (itKeys.hasNext()) { k = itKeys.next(); v = postParameters.get(k); nameValuePairs.add(new BasicNameValuePair(k, v)); } UrlEncodedFormEntity urlEntity = new UrlEncodedFormEntity(nameValuePairs); request.setEntity(urlEntity); } try { Response = client.execute(request,localContext); HttpEntity entity = Response.getEntity(); int statusCode = Response.getStatusLine().getStatusCode(); Log.i(TAG, ""+statusCode); Log.i(TAG, "------------------------------------------------"); try{ InputStream in = (InputStream) entity.getContent(); //Header contentEncoding = Response.getFirstHeader("Content-Encoding"); /*if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) { in = new GZIPInputStream(in); }*/ BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = null; while((line = reader.readLine()) != null){ str.append(line + "\n"); } in.close(); response = str.toString(); Log.i(TAG, "response"+response); } catch(IllegalStateException exc){ exc.printStackTrace(); } } catch(Exception e){ Log.e("log_tag", "Error in http connection "+response); } finally { } return response; }
nikki Apr 24 2018-12-12T00: 00Z
source share