<分区>
当我编译并运行下面的代码时,我抛出了未知的主机异常。
import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
String result="";
// Create a URL for the desired page
URL url = new URL("https://www.google.co.in/?gfe_rd=cr&ei=URzCVNmFKIiBoAPlpoD4CA&gws_rd=ssl#q=jbutton");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
result += str;
}
in.close();
System.out.println(result);
}
如何为上述代码设置代理(Https 和 HTTP)?我在 Eclipse Kepler 中运行上面的代码。