This section provides tutorial example on 2 ways to control HTTP response header line in an ASP script page: Using response.ContentType and response.Charset properties; and using response.AddHeader() method.
Now, I know that my HttpRequestGet.java works correctly. Let me
use it to view ASP tutorial examples to show you 2 ways to control HTTP response header lines
described in a previous section.
The first example, set_content_type.asp, uses the special properties of the response
object:
<script language="vbscript" runat="server">
' set_content_type.asp
' Copyright (c) 2002 by Dr. Herong Yang
response.ContentType = "text/plain"
response.Charset = "ISO-8859-1"
response.Write("<html><body>Hello world!</body></html>")
response.End()
</script>
Note that the Charset property is used as a parameter in Content-Type header line.
In the second example, add_header.asp, I am trying to use the generic methods to
add various header lines:
<script language="vbscript" runat="server">
' add_header.asp
' Copyright (c) 2002 by Dr. Herong Yang
response.AddHeader "Content-Type", "text/xml;charset=UTF-8"
response.AddHeader "Author", "Herong Yang"
response.AddHeader "Author", "Joe Wang"
response.Write "<html><body>Hello world!</body></html>"
response.End
</script>
Here is the response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 28 Dec 2002 13:46:53 GMT
Content-Type: text/xml;charset=UTF-8
Author: Herong Yang
Author: Joe Wang
Connection: Keep-Alive
Content-Length: 38
Content-Type: text/html
Set-Cookie: ASPSESSIONIDQGQGGOSU=IEBDDENBHEFCBLJJKDKAKICH; path=/
Cache-control: private
<html><body>Hello world!</body></html>
Note that:
There are two "Content-Type" header lines, one from my AddHeader() call, and
one added by IIS. So, we can not use AddHeader() to modify the Content-Type header line.
We must use the ContentType property to do this.