
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
800
|
Chapter 14: Web
You are trying to figure out the broad category of the status of the request. You
achieve this by inspecting the
HttpResponse.StatusCode property, comparing it to the
defined status code ranges for HTTP, and returning the appropriate
ResponseCategories
value.
When dealing with
HttpStatusCode, you will notice that there are certain
HttpStatusCode flags that map to the same status code value. An example of this is
HttpStatusCode.Ambiguous and HttpStatusCode.MultipleChoices, which both map to
HTTP status code 300. If you try to use both of these in a switch statement on the
HttpStatusCode, you will get the following error because the C# compiler cannot tell
the difference:
error CS0152: The label 'case 300:' already occurs in this switch statement.
See Also
See HTTP: The Definitive Guide (O’Reilly); see the “HttpStatusCode Enumeration”
topic in the MSDN documentation; and see HTTP/1.1 RFC 2616—Section 10 Sta-
tus Codes: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
14.6 Communicating with a Web Server
Problem
You want to send a request to a web server in the form of a GET or POST request. After
you send the request to a web server, you want to get the results of that request (the
response) from the web server.
Solution
Use the HttpWebRequest class in conjunction with ...