2011/01/15

Java HTTP GET using HttpURLConnection

  1. import java.net.HttpURLConnection;  
  2. import java.net.URLConnection;  
  3. import java.net.URL;  
  4. //....  
  5.   try {  
  6.     URL u = new URL(STR_URL);  
  7.     URLConnection uc = u.openConnection();  
  8.     HttpURLConnection httpuc = (HttpURLConnection)uc;  
  9.     httpuc.setRequestMethod("GET");  
  10.   
  11.     in_stream  = con.getInputStream();  
  12.     out_stream = new FileOutputStream(STR_FILE);  
  13.   
  14.     while (-1 != (len = in_stream.read(buffer))) {  
  15.       out_stream.write(buffer, 0, len);  
  16.     }  
  17.   
  18.     in_stream.close();  
  19.     out_stream.close();  
  20.   
  21.   }catch(Exception e){  
  22.     //..  

0 件のコメント:

コメントを投稿