Create( )
and
GetResponse( )
could have
been written like this:
// First, create a WebRequest to a URI.
WebRequest req = WebRequest.Create("http://www.McGraw-Hill.com");
// Next, send that request and return the response.
WebResponse resp = req.GetResponse();
In cases in which you don’t need to employ a cast to a specific type of protocol implementation,
it is better to use
WebRequest
and
WebResponse
because it allows protocols to be changed
with no impact on your code. However, since all of the examples in this chapter will be using
HTTP, and a few will be using HTTP-specific features, the programs will use
Do'stlaringiz bilan baham: |