大网数据广告活动
Web服务器与PHP

Read and display binary data by using ServerXMLHTTP

· 52CE 我爱测

This article describes how to read and display binary data in ASP using ServerXMLHTTP.

This article shows how to read and display binary data in Active Server Pages (ASP) using ServerXMLHTTP.

Original product version:   Internet Information Services
Original KB number:   303982

Summary

ServerXMLHTTP provides methods and properties for server-safe HTTP access between different Web servers. You can use this object to exchange binary data between these servers through ASP.

More information

The ASP page receives and then displays the binary data using the appropriate Multipurpose Internet Mail Extensions (MIME) type. For example, for .gif images, change the MIME type by using the following:

Response.ContentType = "image/gif"

Note: For Adobe Acrobat files, use application/pdf, or for .jpg images, use image/jpg.

The default behavior for MIME types is to open the document in Microsoft Internet Explorer. Adding the following code prompts the user to save the file or open the file with the associated program:

Content-disposition: attachment; filename=fname.ext

For more information, see How to raise a File Download dialog box for a known MIME type.

The following steps illustrate how to use ServerXMLHTTP to stream a .jpg file to the browser. ServerXMLHTTP retrieves an XML response from an ASP page over HTTP. By using GET, the example sends a request without transferring any data to the Web server. The example writes this response to the browser's output by first informing the browser that the response is an image (image/jpg) and then passing the response directly from the Response object to display it onscreen.

  1. Create a new ASP page, and paste the following code in the page:

    <%@ Language=VBScript %>
    <%
    Response.ContentType = "image/jpeg"
    ' Uncomment to prompt user for download or run with associated program.
    ' Response.AddHeader "content-disposition","attachment;filename=ReadMe.jpg"
    Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")' Point to an image file with adequate access permissions granted
    objHTTP.open "GET", "http://servername/picture.jpg",false
    objHTTP.send
    Response.BinaryWrite objHTTP.ResponseBody
    Set objHTTP = Nothing
    %>
    
  2. Save the file to the Web server.

  3. Browse to the file.

When you use the ServerXMLHTTP object, be aware of the following:

  • Due to threading issues, the ASP page and the file that is being accessed should be in different virtual folders.
  • MSXML 3.0 parser or later should be installed on the server and the proxy configuration utility should be run with appropriate settings.

References

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 09/24/2020
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。