import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpRequestExample {
public static void main(String[] args) {
String urlString = "http://www.biying.com"; //
try {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// 打印网页内容
System.out.println(response.toString());
} else {
System.out.println("GET request not worked");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
07-08
1070
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-12
305
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-24
1053
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-03