getwebpagep.java
来自「java3D game engine design of the source 」· Java 代码 · 共 67 行
JAVA
67 行
// GetWebPageP.java
// Andrew Davison, June 2003, dandrew@ratree.psu.ac.th
/* Retrieve a Web page using URL and URLConnection objects.
Sets hardwired proxy and authorization details.
Uses David W. Croft's Base64Converter class.
Usage:
java GetWebPageP <password> <url>
*/
import java.net.*;
import java.io.*;
import java.util.*;
public class GetWebPageP
{
private static final String LOGIN = "ad"; // modify this
public static void main(String args[]) throws IOException
{
if (args.length != 2) {
System.out.println("usage: java GetWebPageP <password> <url>");
System.exit(0);
}
// set the properties used for proxy support
Properties props = System.getProperties();
props.put("proxySet", "true");
props.put("proxyHost", "cache.psu.ac.th");
props.put("proxyPort", "8080");
System.setProperties(props);
// create a URL and URLConnection
URL url = new URL(args[1]); // URL string
URLConnection conn = url.openConnection();
// encode the "login:password" string
Base64Converter bc = new Base64Converter();
String encoding = bc.encode( LOGIN + ":" + args[0] );
// send the authorization
conn.setRequestProperty("Proxy-Authorization", "Basic " + encoding);
BufferedReader br = new BufferedReader (
new InputStreamReader ( conn.getInputStream() ));
// print first ten lines of contents
int numLine = 0;
String line;
while ( ((line = br.readLine()) != null) && (numLine <= 10) ) {
System.out.println(line);
numLine++;
}
if (line != null)
System.out.println(". . .");
br.close();
System.exit(0);
} // end of main()
} // end GetWebPageP class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?