|
Part:
1
2
3
4
(Continued from previous part...)
3. Command: "java HttpRequestGet /hello.pdf 80" gives us:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 28 Dec 2002 03:29:21 GMT
Content-Type: application/pdf
Accept-Ranges: bytes
Last-Modified: Sat, 28 Dec 2002 21:22:12 GMT
ETag: "01ab9248554c31:903"
Content-Length: 909
%PDF-1.3
% ...
4 0 obj
......
Again, Content-Type was set correctly to "application/pdf" for file name extension
"pdf", as defined in the MIME settings. I truncated the entity body to save some space.
Setting Header Lines Directly in ASP Pages
Let me use the following 2 examples to show you how those methods work.
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>
The response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 28 Dec 2002 23:05:34 GMT
Connection: Keep-Alive
Content-Length: 38
Content-Type: text/plain; Charset=ISO-8859-1
Set-Cookie: ASPSESSIONIDQGQQGVCU=PMOHPEODJIKOLILLKJICNNPI; path=/
Cache-control: private
<html><body>Hello world!</body></html>
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.
- I added two new header lines called "Author".
Sending Binary Files to Browsers
Sometimes, you may want to send to the browser files that are
not in the HTML format, for example, a PDF document, or MS Word Document. In this
case, we have to set Content-Type, Content-Length and other header lines carefully
to provide correct information about the entity body for the client program.
Another challenge of sending these types of files is that they must be handled
in binary mode. The TextStream class offered in c:\winnt\system32\scrrun.dll
can not be used to do this. You must use the Stream class offered in
c:\program files\common files\system\ado\msadox.dll, known as the ADO DLL.
Here is a sample ASP page to show you how to set header lines for different types
of data in the entity body.
(Continued on next part...)
Part:
1
2
3
4
|