Android URL Read getXML(String url)

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

Description

get XML

Declaration

public static String getXML(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.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

import android.util.Log;

public class Main {
    public static String getXML(String url) {
        String responseBody = "";

        try {//w  w  w .j  a v a  2 s. co m
            HttpParams httpParameters = new BasicHttpParams();

            DefaultHttpClient httpClient = new DefaultHttpClient(
                    httpParameters);

            HttpPost httpPost = new HttpPost(url);

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

        } catch (Exception e) {
            e.printStackTrace();
            responseBody = "Exception";
            Log.e("info", "Exception :couldn't connect to server");
            return responseBody;
        }

        return responseBody;

    }
}

Related

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