|
| static Map< String, List< String > > | fetch (URI uri) throws IOException |
| |
| static Socket | openConnection (URI uri) throws UnknownHostException, IOException |
| |
| static void | printGetRequest (PrintWriter writer, URI uri) throws IOException |
| |
| static Map< String, List< String > > | processHttpHeaders (BufferedReader response) throws IOException |
| |
| static Map< String, List< String > > | fetch (String uri) throws URISyntaxException, IOException |
| |
Demonstrates how to use the built-in HttpClient to fetch the headers and content from a URI on the web, as well as how to setup the Socket connections to do the same manually (well suited for web crawling).
- Author
- CS 272 Software Development (University of San Francisco)
- Version
- Spring 2024
◆ fetch() [1/2]
| static Map< String, List< String > > edu.usfca.cs272.HttpsFetcher.fetch |
( |
String | uri | ) |
throws URISyntaxException, IOException |
|
static |
See fetch(URI) for details.
- Parameters
-
- Returns
- a map with the headers and content
- Exceptions
-
| URISyntaxException | if unable to convert String to URI |
| IOException | if unable to fetch headers and content |
- See also
- #fetch(URI)
◆ fetch() [2/2]
| static Map< String, List< String > > edu.usfca.cs272.HttpsFetcher.fetch |
( |
URI | uri | ) |
throws IOException |
|
static |
Fetches the headers and content for the specified URI. The content is placed as a list of all the lines fetched under the "Content" key.
- Parameters
-
- Returns
- a map with the headers and content
- Exceptions
-
| IOException | if unable to fetch headers and content |
- See also
- #openConnection(URI)
-
#printGetRequest(PrintWriter, URI)
-
#processHttpHeaders(BufferedReader)
◆ openConnection()
| static Socket edu.usfca.cs272.HttpsFetcher.openConnection |
( |
URI | uri | ) |
throws UnknownHostException, IOException |
|
static |
Uses a Socket to open a connection to the web server associated with the provided URI. Supports HTTP and HTTPS connections.
- Parameters
-
- Returns
- a socket connection for that URI
- Exceptions
-
| UnknownHostException | if the host is not known |
| IOException | if an I/O error occurs when creating the socket |
- See also
- URL::openConnection()
-
URLConnection
-
HttpURLConnection
◆ printGetRequest()
| static void edu.usfca.cs272.HttpsFetcher.printGetRequest |
( |
PrintWriter | writer, |
|
|
URI | uri ) throws IOException |
|
static |
Writes a simple HTTP v1.1 GET request to the provided socket writer.
- Parameters
-
| writer | a writer created from a socket connection |
| uri | the URI to fetch via the socket connection |
- Exceptions
-
| IOException | if unable to write request to socket |
- See also
- Builder::GET()
◆ processHttpHeaders()
| static Map< String, List< String > > edu.usfca.cs272.HttpsFetcher.processHttpHeaders |
( |
BufferedReader | response | ) |
throws IOException |
|
static |
Gets the header fields from a reader associated with a socket connection. Requires that the socket reader has not yet been used, otherwise this method will return unpredictable results.
- Parameters
-
| response | a reader created from a socket connection |
- Returns
- a map of header fields to a list of header values
- Exceptions
-
| IOException | if unable to read from socket |
- See also
- URLConnection::getHeaderFields()
-
HttpHeaders::map()
The documentation for this class was generated from the following file:
- C:/USFCS/CS272/projects/project-Ravneetsb/src/main/java/edu/usfca/cs272/HttpsFetcher.java