How To Read and Display Binary Data in ASP Using ServerXMLHTTP


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 Active Server Pages (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 additional information, click the article number below to view the article in the Microsoft Knowledge Base:

260519 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 "GET", "http://servername/picture.jpg",false
    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. For more information, see the "References" section.


For the latest information and downloads of MSXML, see the following Microsoft Developer Network (MSDN) Web site:
For more information, see the following Knowledge Base articles:
193998 How To Read and Display Binary Data in ASP
290761 Frequently Asked Questions about ServerXMLHTTP
289481 INFO: Proxy Configuration Must Be Run for ServerXMLHTTP to Work

ID do Artigo: 303982 - Última Revisão: 23 de mar de 2009 - Revisão: 1