我在Eclipse IDE中运行以下java程序:
import java.net.*;
import java.io.*;
public class HH
{
public static void main(String[] args) throws Exception
{
//if i comment out the system properties, and don't set any jvm arguments, the program runs and prints out the html fine.
System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", "8888");
System.setProperty("https.proxyHost", "localhost");
System.setProperty("https.proxyPort", "8888");
URL x = new URL("https://www.google.com");
HttpURLConnection hc = (HttpURLConnection)x.openConnection();
hc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.0)
AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2");
InputStream is = hc.getInputStream();
int u = 0;
byte[] kj = new byte[1024]; …Run Code Online (Sandbox Code Playgroud)