Read from HTTP URL - Android Network

Android examples for Network:HTTP

Description

Read from HTTP URL

Demo Code


//package com.java2s;

import java.io.IOException;

import java.net.HttpURLConnection;

import java.net.URL;

public class Main {
    public static HttpURLConnection httpGetUrlSet(String path, int start,
            int size, String order) {
        HttpURLConnection httpConnection = null;
        try {/* w w  w .j ava  2s.c o m*/
            URL url = new URL(path);
            httpConnection = (HttpURLConnection) url.openConnection();
            httpConnection.setDoInput(true);
            httpConnection.setRequestMethod("GET");
            httpConnection.setConnectTimeout(30000);
            httpConnection.setRequestProperty("appKey", "kxzcsc");
            if (size != -1) {
                httpConnection.setRequestProperty("size",
                        String.valueOf(size));
            }
            if (start != -1) {
                httpConnection.setRequestProperty("start",
                        String.valueOf(start));
            }
            if (!order.trim().equals("")) {
                httpConnection.setRequestProperty("order", order);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return httpConnection;

    }
}

Related Tutorials