load Xml From Network URL - Android Network

Android examples for Network:Network Operation

Description

load Xml From Network URL

Demo Code


//package com.java2s;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static InputStream loadXmlFromNetwork(String urlString)
            throws IOException {

        URL url = new URL(urlString);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(10000);/*from  w  ww .  j a  va  2  s . co m*/
        conn.setConnectTimeout(15000);
        conn.setRequestMethod("GET");
        conn.setDoInput(true);

        conn.connect();

        return conn.getInputStream();
    }
}

Related Tutorials