communicating with the proxy server, getting web-pages behind the proxy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Hello,
I have been programming in java for a very short time and would be very greatful
if any one can help with my problem.
************************************************************************************************************
I want to download a html file from a specified URL.
I've managed to this on internal web-pages but have not succeeded when accessing
web-pages outside the proxy server.
I know that I need to communicate to the proxy server and ask it to get the URL
web page but I don't know how to do this.
I have added the code that I have used to complete the successful bit.

>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
import java.io.*;
import java.net.*;

public class GetURL
{
     public static void main(String[] args) {
          InputStream in = null;
          OutputStream out = null;
          try
          {
               if ( (args.length !=1) && (args.length != 2) )
                    throw new IllegalArgumentException("Wrong number of
arguments");

               URL url = new URL(args[0]);
               in = url.openStream();
               if ( args.length == 2 )
                    out = new FileOutputStream(args[1]);
               else out = System.out;


               byte[] buffer = new byte[4096];
               int bytes_read;
               while ( (bytes_read = in.read(buffer)) != -1 )
                    out.write(buffer, 0, bytes_read);
          }

          catch ( Exception e )
          {
               System.err.println(e);
               System.err.println("Usage: java GetURL <URL> [<filename>]");
          }
          finally
          {
               try
               {
                    in.close(); out.close();
               }
               catch ( Exception e )
               {
               }
          }
     }
}




[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux