Android URL Download getWebContent(String pvUrl)

Here you can find the source of getWebContent(String pvUrl)

Description

get Web Content

Declaration

public static JSONObject getWebContent(String pvUrl) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.json.JSONException;
import org.json.JSONObject;

public class Main {
    public static JSONObject getWebContent(String pvUrl) {
        URL url = null;//from ww w.  j  av  a  2s  . c  o  m
        try {
            url = new URL(pvUrl);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        HttpURLConnection conn;
        JSONObject ret = null;
        String json = null;
        try {
            conn = (HttpURLConnection) url.openConnection();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(conn.getInputStream()));
            json = reader.readLine();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            ret = new JSONObject(json);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return ret;
    }
}

Related

  1. downloadUrl(String urlString)
  2. getJSONResponseFromURL(String url, Hashtable httpGetParams)
  3. downloadJson(URI uri)
  4. getURLString(String urlStr)
  5. getBytesFromUrl(String url)
  6. sendPOST(final String myurl, final String paramns)
  7. connectForMultipart(String url)