Tabnine Logo
HttpResponse.getEntity
Code IndexAdd Tabnine to your IDE (free)

How to use
getEntity
method
in
org.apache.http.HttpResponse

Best Java code snippets using org.apache.http.HttpResponse.getEntity (Showing top 20 results out of 12,591)

Refine searchRefine arrow

  • HttpClient.execute
  • DefaultHttpClient.<init>
  • HttpPost.<init>
  • HttpPost.setEntity
  • HttpEntity.getContent
  • InputStreamReader.<init>
  • BufferedReader.<init>
origin: apache/incubator-dubbo

@Override
public InputStream getInputStream() throws IOException {
  return response == null || response.getEntity() == null ? null : response.getEntity().getContent();
}
origin: stackoverflow.com

HttpClient httpclient = new DefaultHttpClient();
 HttpResponse response = httpclient.execute(new HttpGet(URL));
 StatusLine statusLine = response.getStatusLine();
 if(statusLine.getStatusCode() == HttpStatus.SC_OK){
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   response.getEntity().writeTo(out);
   String responseString = out.toString();
   out.close();
   //..more logic
 } else{
   //Closes the connection.
   response.getEntity().getContent().close();
   throw new IOException(statusLine.getReasonPhrase());
 }
origin: stackoverflow.com

public void post() throws Exception{
   HttpClient client = new DefaultHttpClient();
   HttpPost post = new HttpPost("http://www.baidu.com");
   String xml = "<xml>xxxx</xml>";
   HttpEntity entity = new ByteArrayEntity(xml.getBytes("UTF-8"));
   post.setEntity(entity);
   HttpResponse response = client.execute(post);
   String result = EntityUtils.toString(response.getEntity());
 }
origin: stackoverflow.com

 HttpClient httpclient = new DefaultHttpClient(); // Create HTTP Client
HttpGet httpget = new HttpGet("http://yoururl.com"); // Set the action you want to do
HttpResponse response = httpclient.execute(httpget); // Executeit
HttpEntity entity = response.getEntity(); 
InputStream is = entity.getContent(); // Create an InputStream with the response
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) // Read line by line
  sb.append(line + "\n");

String resString = sb.toString(); // Result is here

is.close(); // Close the stream
origin: pentaho/pentaho-kettle

protected InputStreamReader openStream( String encoding, HttpResponse httpResponse ) throws Exception {
 if ( !Utils.isEmpty( encoding ) ) {
  return new InputStreamReader( httpResponse.getEntity().getContent(), encoding );
 } else {
  return new InputStreamReader( httpResponse.getEntity().getContent() );
 }
}
origin: stackoverflow.com

 URL url=new URL(urlToHit);

HttpPost httppost = new HttpPost(url.toString());
HttpResponse response = LoginScreen.httpClient.execute(httppost); 

// Log.v("response code",""+response.getStatusLine().getStatusCode());

// Get hold of the response entity
HttpEntity entity = response.getEntity();

InputStream instream = null;

if (entity != null) {
  instream = entity.getContent();
}
xr.parse(new InputSource(instream)); //SAX parsing
origin: stackoverflow.com

 HttpEntity entity = MultipartEntityBuilder
  .create()
  .addTextBody("number", "5555555555")
  .addTextBody("clip", "rickroll")
  .addBinaryBody("upload_file", new File(filePath), ContentType.create("application/octet-stream"), "filename")
  .addTextBody("tos", "agree")
  .build();

HttpPost httpPost = new HttpPost("http://some-web-site");
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
HttpEntity result = response.getEntity();
origin: apache/nifi

private JSONObject readJSONFromUrl(String urlString, Map<String, String> headers) throws IOException, JSONException {
  HttpClient httpClient = openConnection();
  HttpGet request = new HttpGet(urlString);
  for (Map.Entry<String, String> entry : headers.entrySet()) {
    request.addHeader(entry.getKey(), entry.getValue());
  }
  HttpResponse response = httpClient.execute(request);
  InputStream content = response.getEntity().getContent();
  return readAllIntoJSONObject(content);
}
origin: dreamhead/moco

private Plain asPlain(org.apache.http.HttpResponse response) throws IOException {
  assertThat(response.getStatusLine().getStatusCode(), is(200));
  HttpEntity entity = response.getEntity();
  MediaType mediaType = MediaType.parse(entity.getContentType().getValue());
  assertThat(mediaType.type(), is("application"));
  assertThat(mediaType.subtype(), is("json"));
  return Jsons.toObject(entity.getContent(), Plain.class);
}
origin: stackoverflow.com

 String encoding = Base64Encoder.encode ("test1:test1");
HttpPost httppost = new HttpPost("http://host:post/test/login");
httppost.setHeader("Authorization", "Basic " + encoding);

System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
origin: nostra13/Android-Universal-Image-Loader

  @Override
  protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
    HttpGet httpRequest = new HttpGet(imageUri);
    HttpResponse response = httpClient.execute(httpRequest);
    HttpEntity entity = response.getEntity();
    BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
    return bufHttpEntity.getContent();
  }
}
origin: stackoverflow.com

 HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);

String html = "";
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
  str.append(line);
}
in.close();
html = str.toString();
origin: stackoverflow.com

 HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://www.a-domain.com/foo/");

// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("param-1", "12345"));
params.add(new BasicNameValuePair("param-2", "Hello!"));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

//Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();

if (entity != null) {
  InputStream instream = entity.getContent();
  try {
    // do something useful
  } finally {
    instream.close();
  }
}
origin: robolectric/robolectric

private static String getStringContent(HttpResponse response) throws IOException {
 return CharStreams.toString(new InputStreamReader(response.getEntity().getContent(), UTF_8));
}
origin: apache/incubator-dubbo

@Override
public InputStream getInputStream() throws IOException {
  return response == null || response.getEntity() == null ? null : response.getEntity().getContent();
}
origin: stackoverflow.com

HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
  response = httpclient.execute(new HttpGet(uri[0]));
  StatusLine statusLine = response.getStatusLine();
  if(statusLine.getStatusCode() == HttpStatus.SC_OK){
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    response.getEntity().writeTo(out);
    responseString = out.toString();
    out.close();
  } else{
    response.getEntity().getContent().close();
    throw new IOException(statusLine.getReasonPhrase());
origin: dreamhead/moco

  private void assertJson(final String url, final String content) throws IOException {
    HttpResponse response = helper.getResponse(url);
    HttpEntity entity = response.getEntity();
    byte[] bytes = ByteStreams.toByteArray(entity.getContent());
    assertThat(new String(bytes), is(content));
    MediaType mediaType = MediaType.parse(entity.getContentType().getValue());
    assertThat(mediaType.type(), is("application"));
    assertThat(mediaType.subtype(), is("json"));
  }
}
origin: stackoverflow.com

 DefaultHttpClient   httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost(http://someJSONUrl/jsonWebService);
// Depends on your web service
httppost.setHeader("Content-type", "application/json");

InputStream inputStream = null;
String result = null;
try {
  HttpResponse response = httpclient.execute(httppost);           
  HttpEntity entity = response.getEntity();

  inputStream = entity.getContent();
  // json is UTF-8 by default
  BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
  StringBuilder sb = new StringBuilder();

  String line = null;
  while ((line = reader.readLine()) != null)
  {
    sb.append(line + "\n");
  }
  result = sb.toString();
} catch (Exception e) { 
  // Oops
}
finally {
  try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
origin: stackoverflow.com

 HttpPost post = new HttpPost("https://yourdomain.com/yourskript.xyz");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("postValue1", "my Value"));
nameValuePairs.add(new BasicNameValuePair("postValue2", "2nd Value"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();

String responseText = EntityUtils.toString(entity);
origin: dreamhead/moco

  @Override
  public void run() throws IOException {
    org.apache.http.HttpResponse httpResponse = helper.getResponse(remoteUrl("/dir/dir.response"));
    String value = httpResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
    assertThat(value, is("text/plain"));
    String content = CharStreams.toString(new InputStreamReader(httpResponse.getEntity().getContent()));
    assertThat(content, is("response from dir"));
  }
});
org.apache.httpHttpResponsegetEntity

Javadoc

Obtains the message entity of this response, if any. The entity is provided by calling #setEntity.

Popular methods of HttpResponse

  • getStatusLine
    Obtains the status line of this response. The status line can be set using one of the #setStatusLine
  • getAllHeaders
  • getFirstHeader
  • getHeaders
  • setEntity
    Associates a response entity with this response. Please note that if an entity has already been set
  • headerIterator
  • getLastHeader
  • setStatusCode
    Updates the status line of this response with a new status code.
  • containsHeader
  • addHeader
  • setHeader
  • getProtocolVersion
  • setHeader,
  • getProtocolVersion,
  • removeHeaders,
  • getParams,
  • setParams,
  • setHeaders,
  • getLocale,
  • setStatusLine,
  • removeHeader

Popular in Java

  • Reading from database using SQL prepared statement
  • requestLocationUpdates (LocationManager)
  • runOnUiThread (Activity)
  • putExtra (Intent)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • Permission (java.security)
    Legacy security code; do not use.
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • JTextField (javax.swing)
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top 17 Plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now