Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using using following code to download the file form receptive source

  private InputStream downloadUrl(String urlString) throws IOException {
    URL url = new URL(urlString);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(10000 /* milliseconds */);
    conn.setConnectTimeout(15000 /* milliseconds */);
    conn.setRequestMethod("GET");
    conn.setDoInput(true);
    // Starts the query  
    Log.v("Start Query", "Stream");
    conn.connect();
    Log.v("End Query", "Stream");
    InputStream stream = conn.getInputStream();    
    Log.v(stream.toString(), "Stream");
    return stream;
}

I got following erros in log

11-09 12:39:59.386: D/SntpClient(73): request time failed: java.net.SocketException: Address family not supported by protocol

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
327 views
Welcome To Ask or Share your Answers For Others

1 Answer

try the following:

      URL url = new URL(urlString);
      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
      conn.setRequestMethod("GET");
      conn.setDoInput(true);
      conn.setReadTimeout(10000);
      conn.setConnectTimeout(15000);

      Log.v("Start Query", "Stream");          
      conn.connect();
      Log.v("End Query", "Stream");
      //read the result from the server
      BufferedReader rdr  = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      StringBuilder sbr = new StringBuilder();

      while ((line = rdr.readLine()) != null)
      {
          sbr.append(line + '
');
      }

      Log.v(sbr.toString(), "Stream");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...