Introduction
- The WebRequest Class
- The WebResponse Class
- Reading HTTP Response Headers
- Setting HTTP Request Headers
- Managing HTTP Timeouts
The connection between a bot and a web server is very important. In the previous chapters this link was established using either a Socket object or through a Stream. In summary, the two ways to open a connection to a web server are via:
- Socket, or
- WebRequest and WebResponse
In the previous chapter you saw how to open a stream to a URL. Review the following commands.
HttpWebRequest http = (HttpWebRequest)HttpWebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)http.GetResponse(); Stream stream = response.GetResponseStream();
In the previous chapter we used the stream to read data from URL. You will also notice that there are two other objects created in addition to the stream. The additional objects created are a WebRequest and an HttpWebResponse. These objects allow you to perform additional operations on the HTTP connection, other than simply reading from it. These operations include:
- Reading data from the URL
- Posting data to the URL
- Setting client headers
- Reading server headers
- Setting socket parameters
In the next several two sections the HttpWebRequest and HttpWebResponse will be examined.












