欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP:Response.ContentType

程序员文章站 2022-11-21 22:35:31
response.contenttype 是用来控制输出的文件类型的。服务器送给客户端的数据包类型可以是text/html文本,也可以是gif...

response.contenttype 是用来控制输出的文件类型的。

服务器送给客户端的数据包类型可以是text/html文本,也可以是gif/jpeg图形文件,所以每次传输前,我们都必须告知客户端将要传输的文件类型,一般默认情况下为“text/html”类型。
<% response.contenttype = "text/html" %>
<% response.contenttype = "image/gif" %>
<% response.contenttype = "image/jpeg" %>

用于作为文本内容返回而不是已解释的 html 语句
response.contenttype = "text/plain"
<%
response.contenttype = "text/plain"
response.write(now()&"会被执行么?")
%>

你可以注意到:页面提供下载,页面中的asp内容被解释执行了的程序文件以xls文件被提供下载
response.contenttype = "application/vnd.ms-excel"
<%
response.contenttype = "application/vnd.ms-excel"
response.write("本页面调试会出现下载对话框提供下载,保存类型为xls")
%>

实现歌曲连续播放
response.contenttype="audio/x-pn-realaudio"
<%
dim ramstr
ramstr=""
set rs=server.createobject("adodb.recordset")
sql="xxxxxxxxxxx"
rs.open sql,conn,1,3 conn已定义
do while not rs.eof
ramstr=ramstr&rs("url")&vbcrlf
rs.movenext
loop
rs.close
response.contenttype="audio/x-pn-realaudio"
response.contenttype="audio/x-mpegurl"
response.write ramstr
%>

response.write 输出的时候,由于定义了response.contenttype 所以输出歌曲地址的时候会自动调用符合相应格式的软件来播放歌曲,不过前提是播放歌曲的软件必须先安装的。response.write 输出的时候,由于定义了response.contenttype 所以输出歌曲地址的时候会自动调用符合相应格式的软件来播放歌曲,不过前提是播放歌曲的软件必须先安装的。