1. Are you ready for the Galaxy S20? Here is everything we know so far!

Apps HttpConnection in Android

Discussion in 'Android Development' started by apjustin, Feb 24, 2011.

  1. apjustin

    apjustin Lurker
    Thread Starter

    Hi all,

    I have to port one application from Blackberry to Android

    I'm new to Droid and I couldn't find out a simple way to establish a HttpConnection

    This is my Blackberry code

    Can anyone tell me the Droid way of implementing this in a simplest way like using HttpConnection?
     

    Advertisement

  2. smita

    smita Newbie

    String sUrl="http://www.location.de/xml.zip";
    int test = -1;

    HttpURLConnection conn=null;
    BufferedReader rd;
    try
    {
    url = new URL(sUrl);

    try {
    URLConnection urlconn =(URLConnection)url.openConnection();
    if (!(urlconn instanceof HttpURLConnection))
    throw new IOException("Not an HTTP connection");

    conn = (HttpURLConnection)urlconn;
    conn.setRequestMethod("GET");
    conn.connect();
    test=conn.getResponseCode();

    }
    catch (IOException e1)
    {
    Toast.makeText(this,"e1"+e1.toString() ,Toast.LENGTH_LONG).show();

    }

    try {
    // InputStream in=new InputStream(conn.getInputStream());
    // parse(conn.getInputStream());
    // InputStreamReader r=new InputStreamReader(conn.getInputStream());




    rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

    String line;
    while ((line = rd.readLine()) != null)
    {
    response=line;
    Toast.makeText(this, response,Toast.LENGTH_LONG).show();
    }

    }

    catch (IOException e)
    {

    // TODO Auto-generated catch block
    Toast.makeText(this,"e2"+e.toString() ,Toast.LENGTH_LONG).show();
    e.printStackTrace();
    }

    }
    catch (MalformedURLException e)
    {
    // TODO Auto-generated catch block
    Toast.makeText(this,"e3"+e.toString() ,Toast.LENGTH_LONG).show();
    e.printStackTrace();
    }
     
    apjustin likes this.
Loading...
Similar Threads - HttpConnection Android
  1. Steven58
    Replies:
    0
    Views:
    0
  2. Cyberdev
    Replies:
    3
    Views:
    67
  3. Guitarist
    Replies:
    0
    Views:
    54
  4. Sarat chandra Poluri
    Replies:
    1
    Views:
    133
  5. markdoc
    Replies:
    5
    Views:
    116
  6. Rob
    Replies:
    11
    Views:
    229
  7. Kamilek123
    Replies:
    2
    Views:
    334
  8. Android News
    Replies:
    0
    Views:
    120
  9. Android News
    Replies:
    0
    Views:
    111
  10. Android News
    Replies:
    0
    Views:
    200

Share This Page

Loading...