HTML and CSS Reference
In-Depth Information
Listing 4-8. Content Negotiation in C# in ASP .NET
string accept = Request.ServerVariables["HTTP_ACCEPT"];
string ua = Request.ServerVariables["HTTP_USER_AGENT"];
if (accept != null && ua != null) {
if (accept.IndexOf("application/xhtml+xml") >=0 || ua.IndexOf("W3C_Validator") >= 0) {
Response.ContentType = "application/xhtml+xml";
The previous codes perform content negotiation with their own syntax. In PHP, for example, the server
variables contained in the $_SERVER array are used to evaluate the HTTP Accept header of the user agent and set the
appropriate MIME type via the header function (Listing 4-6).
URIs, URLs, and URNs
A Uniform Resource Identifier ( URI ) is a character string that identifies a name or a resource on the Internet (RFC 2396
[53]). URIs can be classified as Uniform Resource Locators ( URLs ; RFC 1738 [54]), Uniform Resource Names ( URNs ),
or both. A URN defines the identity of a resource, while the URL provides a method for finding it (including protocol
and path). URIs are often used incorrectly as the synonym for URL, although URI is a wider term (RFC 3305 [55]).
Both the URN and the URL are subsets of URI, but they are generally disjoint sets.
The best-known examples for URLs are the web site addresses on the World Wide Web. Listing 4-9 shows the
general URL syntax.
Listing 4-9. URL Syntax
The protocol ( scheme name ) is followed by a colon. The other parts of URLs depend on the scheme being used.
Usually there is a domain name or an IP address, an optional port number, and an optional path to the resource
or script. Programs such as PHP or CGI scripts might have a query string. The end of the URL can be an optional
fragment identifier.
Since many of these sections are optional, one or more of them are omitted. Listing 4-10 shows an example,
where http is the protocol, is the domain, and the path leads to the shop directory.
Listing 4-10. A Typical URL
URI references are widely used in markup languages, for example, as the attribute value of the href attribute on
the a element in HTML or as the system identifier after the SYSTEM keyword in an XML DTD.
Persistent URIs
Everyone knows the frustrating feeling when a web site address typed into the address bar of the browser is not
available, or when clicking on a hyperlink generates a File not found error.
There are many reasons why URIs can be temporarily or permanently unavailable. The simplest reason is that
the requested files have been moved to another folder or they have removed from the server. Another reason is
that technologies applied on the server have been changed. For example, a company used CGI scripts but recently
changed to Perl, and the URIs of the files located in the cgi-bin directory have become obsolete.
Search WWH ::

Custom Search