Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I save ResponseBody from WinHTTP to a file and then how can I open it up again?

Posted on 2005-04-21
7
Medium Priority
?
1,695 Views
Last Modified: 2008-01-09
kiddanger was quite helpful and helped me make the following code work:

=======================================
<%@ Language=VBScript %>
<%          
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "cache-control", "no-store"
Response.ContentType = "image/gif"
Dim HTTP, strHTML
set HTTP = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
'Google image used as an example only
HTTP.Open "GET", "http://www.google.com/intl/en/images/logo.gif"   
HTTP.Send
strHTML = HTTP.responseBody
Response.BinaryWrite strHTML
%>
=======================================

Basically, it the code above will display an ASP page as an image
captured from a remote  URL.

Now, I would like to know how to save the HTTP.ResponseBody
to a gif/jpg/png file on the hard drive.

The follow up to that would be opening the file from the HDD and
displaying it again just like the original code does from the Remote
URL resource.



0
Comment
Question by:ScribbleMeat
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Expert Comment

by:neeraj523
ID: 13831590
Hello

here is the way to save gif image at ur harddisk

==========================================================================
<%          
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "cache-control", "no-store"
Response.ContentType = "image/gif"
Dim HTTP, strHTML
set HTTP = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
'Google image used as an example only
HTTP.Open "GET", "http://www.google.com/intl/en/images/logo.gif"     
HTTP.Send
strHTML = HTTP.responseBody
Response.BinaryWrite strHTML


SaveBinaryData Server.MapPath("/") & "/logo.gif" , strHTML

Function SaveBinaryData(FileName, ByteArray)
  Const adTypeBinary = 1
  Const adSaveCreateOverWrite = 2
 
  'Create Stream object
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
 
  'Specify stream type - we want To save binary data.
  BinaryStream.Type = adTypeBinary
 
  'Open the stream And write binary data To the object
  BinaryStream.Open
  BinaryStream.Write ByteArray
 
  'Save binary data To disk
  BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
%>
==========================================================================

Hope it will help

neeraj523
0
 

Author Comment

by:ScribbleMeat
ID: 13831641
neeraj523,

That's cool, but I was hoping to use the FileSystemObject not ADO.

-- ScribbleMeat
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 13831722


fileSystemObject dsnt support binary data... ADO is also a default component comes with Windows OS just like fileSystemObject.. so i don't think any issue in using ADo for this purpose..

neeraj523
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ScribbleMeat
ID: 13831935
Okay, well it will be run server-side, so it shouldn't be a problem.

One thing you left out was re-opening the file and outputing it with Response.BinaryWrite.

0
 
LVL 22

Expert Comment

by:neeraj523
ID: 13832539

why it is needed ?? code is already first printing the image file on the page and then saving ti into a file on hard disk

is it not what you were looking for ??

neeraj523
0
 
LVL 14

Accepted Solution

by:
kiddanger earned 2000 total points
ID: 13844660
Hi Scribble...

I had to separate files to be able to show you the source online.

The file that does the work is getimage.asp.  You can easily call it with:

<img src="getimage.asp" />

This makes it easier to mix other content which makes  it easier to put a link so I can show you the ASP source.  If you go to this file:
http://kiddanger.com/lab/getaspimage.asp

...and view the source, you'll see it is different than if you click on the link for "View Source" at the bottom left of that page.  That gives you the source of http://kiddanger.com/lab/getimage.asp.

The problem I ran into is when you change your ContentType to be image/gif, you don't get to see errors when trying to debug.
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13903550
Thank you Scribble.  (O:=
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question