home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / bb98.exe / HTTPGet.java < prev    next >
Text File  |  2002-11-09  |  2KB  |  89 lines

  1. //
  2. // The contents of this file are subject to the BadBlue End User License
  3. // Agreement (the "EULA"); you may not use this file except in
  4. // compliance with the EULA.  You may obtain a copy of the EULA at
  5. // http://badblue.com/down.htm .
  6. //
  7. // Software distributed under the EULA is distributed on an "AS IS" basis,
  8. // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the EULA
  9. // for the specific language governing rights and limitations under the
  10. // EULA.
  11. //
  12. // The Initial Developer of this code under the EULA is Working Resources,
  13. // Inc., Atlanta, GA  UNITED STATES.  All Rights Reserved.
  14. //
  15.  
  16. //
  17. package ShareOffice;
  18.  
  19. //
  20. import java.net.*;
  21. import java.io.*;
  22.  
  23. //
  24. public class HTTPGet {
  25.     //
  26.     public HTTPGet() {
  27.     }
  28.     //
  29.     public String Read(String sURL) {
  30.         try {
  31.             URL u = new URL(sURL);
  32.             InputStream is = u.openStream();
  33.             InputStreamReader isr = new InputStreamReader(is);
  34.             BufferedReader br = new BufferedReader(isr);
  35.             String s = "";
  36.             String sLine;
  37.             while ((sLine = br.readLine()) != null) {
  38.                 // System.out.println(sLine);
  39.                 s += sLine;
  40.             }
  41.             return (s);
  42.         } catch (Exception e) {
  43.             return "Error, no data available: " +
  44.             e.getMessage();
  45.         }
  46.     }
  47.     //
  48.     public String Read(String sURL, String sUsername, String sPassword) {
  49.         try {
  50.             URL u = new URL(sURL);
  51.             String sUP = sUsername + ":" + sPassword;
  52.             String sUPencoded = new sun.misc.BASE64Encoder().encode(sUP.getBytes());
  53.             URLConnection urlConn = u.openConnection();
  54.             urlConn.setRequestProperty("Authorization", "Basic " + sUPencoded);
  55.             urlConn.setDoInput(true);
  56.             urlConn.setUseCaches (false);
  57.             urlConn.setDoOutput(true);
  58.             DataOutputStream printout = new DataOutputStream(urlConn.getOutputStream());
  59.             int nCursor;
  60.             String sContent = "";
  61.             if ((nCursor = sURL.indexOf('?')) >= 0) {
  62.                 sContent = sURL.substring(nCursor + 1);
  63.             }
  64.             printout.writeBytes(sContent);
  65.             printout.flush();
  66.             printout.close();
  67.             // DataInputStream input = new DataInputStream(urlConn.getInputStream());
  68.             BufferedReader input = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); 
  69.             String s = "";
  70.             String sLine;
  71.             while (null != ((sLine = input.readLine()))) {
  72.                 // System.out.println(sLine);
  73.                 s += sLine;
  74.             }
  75.             input.close();
  76.             return (s);
  77.         } catch (Exception e) {
  78.             return "Error, no data available: " +
  79.             e.getMessage();
  80.         }
  81.     }
  82.  
  83.     //    Private members.
  84.     //
  85. }
  86.  
  87. //    <EOF>
  88. //
  89.