Android URL Read getStringFromUrl(String url)

Here you can find the source of getStringFromUrl(String url)

Description

get String From Url

Declaration

public static String getStringFromUrl(String url) 

Method Source Code

//package com.java2s;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class Main {
    public static String getStringFromUrl(String url) {
        try {/*  www  .  ja  v  a  2 s  .  c  om*/
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();

            return EntityUtils.toString(httpEntity);
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. getResource(String filename)
  2. readFile(URL url)
  3. getXML(String url)
  4. readXmlFromUrl(String address)
  5. getFileDateTime(URL url)
  6. readTextFromUri(Context c, Uri uri)
  7. getHtmlByteArray(final String url)