HttpURLConnection class from java.net
package can be used to send Java HTTP Request programmatically. Today we will learn how to use HttpURLConnection
in java program to send GET and POST requests and then print the response.
java.net
包中的HttpURLConnection类可用于以编程方式发送Java HTTP请求。 今天,我们将学习如何在Java程序中使用HttpURLConnection
来发送GET和POST请求,然后打印响应。
Java HTTP请求 (Java HTTP Request)
For our HttpURLConnection example, I am using sample project from Spring MVC Tutorial because it has URLs for GET and POST HTTP methods. Below are the images for this web application, I have deployed it on my localhost tomcat server.
对于我们的HttpURLConnection示例,我正在使用Spring MVC教程中的示例项目,因为它具有GET和POST HTTP方法的URL。 下面是此Web应用程序的图像,我已将其部署在localhost tomcat服务器上。
Java HTTP GET Request for Login Page
Java HTTP GET登录页面请求