Back to index

wims  3.65+svn20090927
url.java
Go to the documentation of this file.
00001 import java.applet.Applet;
00002 import java.io.InputStream;
00003 import java.io.OutputStream;
00004 import java.io.InputStreamReader;
00005 import java.io.BufferedReader;
00006 import java.net.URL;
00007 import java.net.URLConnection;
00008 
00009 public class url extends Applet {
00010        private static String auth_cookie = null;
00011        private static StringBuffer c;
00012        public String readURL( String urlStr, boolean cache, String data, String referer) {
00013               c = new StringBuffer(8192);
00014               try {
00015                      if ( cache == false ) urlStr.concat((urlStr.indexOf('?')==-1)?"&":"?").concat("stopCache=").concat(Long.toString(System.currentTimeMillis()));
00016                      URLConnection uc = new URL( urlStr ).openConnection();
00017                      int len = data.length();
00018                      if (len>0) uc.setDoInput( true );
00019                      uc.setDoOutput( true );
00020                      uc.setRequestProperty( "Referer", referer );
00021                      if ( cache == false ) uc.setUseCaches( false );
00022                      if (len>0) {
00023                             byte[] contentBytes = data.getBytes();
00024                             uc.setRequestProperty( "Content-length", Integer.toString( len ) );
00025                             uc.setRequestProperty( "Content-type", "application/x-www-form-urlencoded" );
00026                             OutputStream os = uc.getOutputStream();
00027                             os.write( contentBytes );
00028                             os.flush();
00029                      };
00030                      InputStream is = uc.getInputStream();
00031                      BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
00032                      String line;
00033                      while ((line = buffer.readLine())!=null) c.append(line+"\n");
00034               } catch ( Exception e ) {
00035                      c.append("Error: " + e);
00036               };
00037               return c.toString();
00038        };
00039 };