HttpPost httpPost = new HttpPost(url); StringEntity se = new StringEntity(envelope,HTTP.UTF_8); httpPost.setEntity(se); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = 3000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); BasicHttpResponse httpResponse = (BasicHttpResponse) httpClient.execute(httpPost); HttpEntity entity = httpResponse.getEntity(); return entity;
EntityUtils.consume(httpResponse.getEntity()); } catch (IOException e) {/*consume quietly*/}
/** * {@inheritDoc} */ @Override public HttpEntity getEntity() { return (response != null ? response.getEntity() : super.getEntity()); }
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("Password", "My password")); nameValuePairs.add(new BasicNameValuePair("Mail", "My mail")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request BasicHttpResponse response = (BasicHttpResponse) httpclient.execute(httppost); HttpEntity entity = response.getEntity();
HttpPost httpPost = new HttpPost(url); StringEntity se = new StringEntity(envelope,HTTP.UTF_8); httpPost.setEntity(se); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = 3000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); BasicHttpResponse httpResponse = (BasicHttpResponse) httpClient.execute(httpPost); HttpEntity entity = httpResponse.getEntity();
HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(YOUR URL COMES HERE); String responseBody; try { BasicHttpResponse response = (BasicHttpResponse) httpclient.execute(httppost); HttpEntity entity = response.getEntity(); responseBody = EntityUtils.toString(entity); } catch (ClientProtocolException e) { Log.w("com.name.pkg", e); return 0; } catch (IOException e) { Log.w("com.name.pkg", e); return 0; } return 1; }
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(4); nameValuePair.add(new BasicNameValuePair("page", "/OrderHandlingServlet?api=login")); nameValuePair.add(new BasicNameValuePair("txtDomain", "MyDomain")); nameValuePair.add(new BasicNameValuePair("txtUid", "user1")); nameValuePair.add(new BasicNameValuePair("txtPwd", "pwd1")); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, INSERTCONNECTIONTIMEOUT); HttpClient client = new DefaultHttpClient(params); HttpPost request = new HttpPost(URL);//put url here request.setEntity(new UrlEncodedFormEntity(nameValuePair)); BasicHttpResponse httpResponse = (BasicHttpResponse) client.execute(request); String data = StreamToString(httpResponse.getEntity().getContent());
try { HttpClient httpclient = getNewHttpClient(true); HttpPost httppost = new HttpPost(url); httppost.setHeader("Content-Type", "text/xml"); BasicHttpResponse httpResponse = null; httpResponse = (BasicHttpResponse) httpclient.execute(httppost); InputStream is = httpResponse.getEntity().getContent(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
HttpPost hPost = new HttpPost(url); StringEntity se = new StringEntity(envelope,HTTP.UTF_8); hPost.setEntity(se); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = 3000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient.execute(hPost); HttpEntity entity = httpResponse.getEntity(); return entity;
HttpPost httpPost = new HttpPost(url); StringEntity se = new StringEntity(envelope,HTTP.UTF_8); httpPost.setEntity(se); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = 3000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); BasicHttpResponse httpResponse = (BasicHttpResponse) httpClient.execute(httpPost); HttpEntity entity = httpResponse.getEntity(); return entity;
private String SendDataFromAndroidDevice() { String result = ""; try { HttpClient httpclient = new DefaultHttpClient(); HttpGet getMethod = new HttpGet("your url + data appended"); BufferedReader in = null; BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient .execute(getMethod); in = new BufferedReader(new InputStreamReader(httpResponse .getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; while ((line = in.readLine()) != null) { sb.append(line); } in.close(); result = sb.toString(); } catch (Exception e) { e.printStackTrace(); } return result; }
private String SendDataFromAndroidDevice() { String result = ""; try { HttpClient httpclient = new DefaultHttpClient(); HttpGet getMethod = new HttpGet("your url + data appended"); BufferedReader in = null; BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient .execute(getMethod); in = new BufferedReader(new InputStreamReader(httpResponse .getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; while ((line = in.readLine()) != null) { sb.append(line); } in.close(); result = sb.toString(); } catch (Exception e) { e.printStackTrace(); } return result; }
HttpPost httppost = new HttpPost(URL); StringEntity se; String SOAPRequestXML = ""; try { SOAPRequestXML="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\"><soapenv:Header/><soapenv:Body><tem:wmtdEstadoActuadoIluminacion><tem:strIp>192.168.1.121</tem:strIp><tem:strDispositivo>Nexus 6</tem:strDispositivo><tem:strUsuario>Alonso</tem:strUsuario><tem:intTipoUs>1</tem:intTipoUs><tem:intPuerto>85</tem:intPuerto><tem:strIpConexionArduino>192.168.1.120</tem:strIpConexionArduino><tem:intPuertoConexionArduino>1234</tem:intPuertoConexionArduino></tem:wmtdEstadoActuadoIluminacion></soapenv:Body></soapenv:Envelope>"; se = new StringEntity(SOAPRequestXML, HTTP.UTF_8); se.setContentType("text/xml"); httppost.setHeader("Accept-Charset","utf-8"); httppost.setHeader("soapaction", SOAP_ACTION); httppost.setEntity(se); HttpClient httpclient = new DefaultHttpClient(); BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient.execute(httppost); HttpEntity resEntity = httpResponse.getEntity(); Log.e("RESPONSE: ", EntityUtils.toString(resEntity)); } catch (Exception e) { e.printStackTrace(); }
private String SendDataFromAndroidDevice() { String result = ""; try { HttpClient httpclient = new DefaultHttpClient(); HttpGet getMethod = new HttpGet("your url + data appended"); BufferedReader in = null; BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient .execute(getMethod); in = new BufferedReader(new InputStreamReader(httpResponse .getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; while ((line = in.readLine()) != null) { sb.append(line); } in.close(); result = sb.toString(); } catch (Exception e) { e.printStackTrace(); } return result; }
InputStream is = response.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(is));
BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient.execute(httppost); HttpEntity entity = httpResponse.getEntity(); bis = entity.getContent(); result = readResponse();