package aaa;
import java.net.HttpURLConnection;
import java.net.URL;
public class UrlTest {
public static void main(String[] args) throws Exception{
URL url = new URL("http://www.baidu.com/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
int state = conn.getResponseCode();
System.out.println(state);//请求的响应状态值;
System.out.println(conn.getURL().toString());//请求地址
}
}
import java.net.HttpURLConnection;
import java.net.URL;
public class UrlTest {
public static void main(String[] args) throws Exception{
URL url = new URL("http://www.baidu.com/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
int state = conn.getResponseCode();
System.out.println(state);//请求的响应状态值;
System.out.println(conn.getURL().toString());//请求地址
}
}