Read a Web Page by Connecting to a Final Server Through a Proxy Server

Read a Web Page by Connecting to a Final Server Through a Proxy Server

This code uses the new J2SE 5.0 classes and to connect to a final server through a proxy server in order to view a Web page. The Proxy class represents a proxy setting (proxy protocol and proxy address) and the Proxy.Type class represents the proxy type. This type can be:

DIRECT - no proxy;HTTP - high level protocol such FTP,HTTPSOCKS - SOCKS (V4 or V5)

In this example, the proxy type is HTTP and the proxy address is localhost, but it can be any other proxy. For opening a connection to that proxy, the code uses the openConnection(Proxy proxy) method of the URL class.

Before opening the connection, you must supply the URL that you want to access by replacing “the final server URL.” The coonection is then made through the proxy server. The next step is to call the getInputStream method to read the Web page specified by the URL. After that, use BufferedReader to display the page content on the screen:

import*; import*; import java.util.*; class read{ public read(){} BufferedReader buffer=null;      String linie=null; URLConnection URLcon=null; URL url=null; InputStream IS=null; public void getURLContent()             {            try {              InetAddress addr=InetAddress.getLocalHost(); //or use getByName("proxy host");             InetSocketAddress ISA=new InetSocketAddress(addr,port);//where port is the proxy port     proxy=new,ISA); //you may also use SOCKS or DIRECT types                                url=new URL("the final server URL");                               URLcon = url.openConnection(proxy);                                                IS=URLcon.getInputStream();                   buffer=new BufferedReader(new InputStreamReader(IS));                     while((linie=buffer.readLine())!=null)                                        {                                 System.out.println(linie);                               }                 buffer.close();                     }catch(MalformedURLException e)                             {System.out.println("Eroare:"+e.getMessage());                 }catch(IOException e)                       {System.out.println("Eroare:"+e.getMessage());}                           } } public class ReadURLToProxy{         public static void main(String[] args)       {         read t=new read();       t.getURLContent();         } }" 
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes