In this chapter, we examined the various Java approaches that can be used to develop HTTP client/server applications. Communication using HTTP is a common practice. Understanding how Java supports this process is a valuable skill to possess.
We started with an overview of HTTP messages. We examined the format of the initial request and response lines. Headers lines were also examined, which are used to convey information about the message. An optional message body may appear in an HTTP message. This is more common in a response where the body is often an HTML document.
We demonstrated how a client/server can be developed using simple socket. While possible, this approach requires a lot of work to develop a fully functional HTTP server. This discussion was followed by the use of the HTTPServer
and HttpURLConnection
classes to support a server and client, respectively. The use of these classes made the development process much easier.
There are a number of open source Java-based HTTP...