Link to home
Start Free TrialLog in
Avatar of skij
skijFlag for Canada

asked on

Classic ASP: Write Binary PDF to File

The following code returns an error.  I think the problem might be related to the fact that I am trying to retrieve and write a binary PDF file.  No error is returned when I use this code to retrieve and write a text file.
<%

 url = "https://www.cl.cam.ac.uk/~mgk25/ucs/UTF-8-Plan9-paper.pdf" 
 set pdfhttp = CreateObject("MSXML2.ServerXMLHTTP") 
 pdfhttp.open "POST", url, false 
 pdfhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
 dim pdata
 pdat = "x=1&y=2&z=3" 
 pdfhttp.send pdat

 set oFs = server.createobject("Scripting.FileSystemObject")
 set oTextFile = oFs.OpenTextFile(Server.MapPath(".") & "\Test.pdf", 2, True)
 oTextFile.Write pdfhttp.responseText
 oTextFile.Close
 set oTextFile = nothing
 set oFS = nothing

 Response.Write(pdfhttp.responseText)
 Response.End

%>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of zc2
zc2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skij

ASKER

Thanks!  Also, thank you for pointing out that responseBody should be used.
You're welcome!