problem with reading a url

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

problem with reading a url

Postby androidbeginner » Tue Feb 05, 2008 7:17 am

hi..can u please help me..am trying to access data from a url..i have read ur tutorial about "parsing xml from the net using xml parser".. itried the same program..but each time it says:" Host is unresolved:www.anddev.org:80"..what do i do???
it is very urgent..plass relpy soon...
thanks!!
androidbeginner
Junior Developer
Junior Developer
 
Posts: 17
Joined: Tue Feb 05, 2008 7:10 am

Top

Postby plusminus » Tue Feb 05, 2008 9:28 am

Hello androidbeginner,

looks strange..
A.) Can you browse anddev.org from within the emulators browser :?:
B.) Can you browse ANY site from within the emulators browser :?:

If only B.) just to grab any other homepage ( like i.e. this one http://www.heise.de/imonitor/view.phtml )

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby androidbeginner » Tue Feb 05, 2008 10:15 am

Hi plusminus..
here is my source code.This gives me a blank screen when executed..can u see where am i going wrong..

Thanks!!



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2.  
  3. import android.os.Bundle;
  4.  
  5.  
  6.  
  7.  
  8.  
  9.         import java.io.BufferedInputStream;
  10.  
  11.         import java.io.InputStream;
  12.  
  13.         import java.net.InetAddress;
  14.  
  15.         import java.net.Proxy;
  16.  
  17.         import java.net.Socket;
  18.  
  19.         import java.net.SocketAddress;
  20.  
  21.         import java.net.URL;
  22.  
  23.         import java.net.URLConnection;
  24.  
  25.         import org.apache.http.util.ByteArrayBuffer;
  26.  
  27.         import android.widget.TextView;
  28.  
  29.  
  30.  
  31.         public class webappl extends Activity {
  32.  
  33.              @Override
  34.  
  35.              public void onCreate(Bundle icicle) {
  36.  
  37.                  super.onCreate(icicle);
  38.  
  39.                
  40.  
  41.                   /* We will show the data we read in a TextView. */
  42.  
  43.                   TextView tv = new TextView(this);
  44.  
  45.                   String myString = null;
  46.  
  47.                   System.setProperty("http.proxyHost"," 129.188.69.100 ");
  48.  
  49.                           System.setProperty("http.proxyPort","1080");
  50.  
  51.                  
  52.  
  53.                          
  54.  
  55.                   try {
  56.  
  57.                          
  58.  
  59.                          
  60.  
  61.                        /* Define the URL we want to load data from. */
  62.  
  63.                        URL myURL = new URL(
  64.  
  65.                          "http://www.anddev.org/images/tut/basic/getdatafromtheweb/loadme.txt");
  66.  
  67.                        Socket s=new Socket("85.13.138.161",80);
  68.  
  69.                 SocketAddress sa=s.getLocalSocketAddress();
  70.  
  71.                 Proxy p=new Proxy(Proxy.Type.HTTP,sa);    
  72.  
  73.                        /* Open a connection to that URL. */
  74.  
  75.                        URLConnection ucon = myURL.openConnection(p);
  76.  
  77.  
  78.  
  79.                        /* Define InputStreams to read
  80.  
  81.                         * from the URLConnection. */
  82.  
  83.                        InputStream is = ucon.getInputStream();
  84.  
  85.                        BufferedInputStream bis = new BufferedInputStream(is);
  86.  
  87.                        
  88.  
  89.                        /* Read bytes to the Buffer until
  90.  
  91.                         * there is nothing more to read(-1). */
  92.  
  93.                        ByteArrayBuffer baf = new ByteArrayBuffer(50);
  94.  
  95.                        int current = 0;
  96.  
  97.                        while((current = bis.read()) != -1){
  98.  
  99.                             baf.append((byte)current);
  100.  
  101.                        }
  102.  
  103.  
  104.  
  105.                        /* Convert the Bytes read to a String. */
  106.  
  107.                        myString = new String(baf.toByteArray());
  108.  
  109.                   } catch (Exception e) {
  110.  
  111.                        /* On any Error we want to display it. */
  112.  
  113.                        myString = e.getMessage();
  114.  
  115.                   }
  116.  
  117.                   /* Show the String on the GUI. */
  118.  
  119.                   tv.setText(myString);
  120.  
  121.                   this.setContentView(tv);
  122.  
  123.              }
  124.  
  125.         }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4
androidbeginner
Junior Developer
Junior Developer
 
Posts: 17
Joined: Tue Feb 05, 2008 7:10 am

Postby plusminus » Tue Feb 05, 2008 10:41 am

Sorry androidbeginner,

looks very much like a proxy-problem.
But I'm 0% in the proxy-issue, because I am behind none :(

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 6 guests