Microsoft KB Archive/303982

= How To Read and Display Binary Data in ASP Using ServerXMLHTTP =

Article ID: 303982

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft XML Core Services 4.0
 * Microsoft XML Parser 3.0 Service Pack 1
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q303982



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 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 = &quot;image/gif&quot; NOTE: For Adobe Acrobat files use &quot;application/pdf&quot;, or for .jpg images use &quot;image/jpg&quot;.

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 (&quot;image/jpg&quot;) and then passing the response directly from the Response object to display it onscreen.   Create a new ASP page, and paste the following code in the page: <%@ Language=VBScript %> <% Response.ContentType = &quot;image/jpeg&quot; ' Uncomment to prompt user for download or run with associated program. ' Response.AddHeader &quot;content-disposition&quot;,&quot;attachment;filename=ReadMe.jpg&quot; Set objHTTP = Server.CreateObject(&quot;Msxml2.ServerXMLHTTP&quot;) ' Point to an image file with adequate access permissions granted objHTTP.open &quot;GET&quot;, &quot;http://servername/picture.jpg&quot;,false objHTTP.send Response.BinaryWrite objHTTP.ResponseBody Set objHTTP = Nothing %>                     Save the file to the Web server. 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 &quot;References&quot; section.

