使用vbscript下载并保存网页

使用vbscript下载并保存网页,vbscript,asp-classic,save,download,Vbscript,Asp Classic,Save,Download,我试图让用户选择下载和保存一个网页到任何他们想要的地方。我一直在寻找解决办法,但似乎没有任何效果。我在经典asp中使用vbscript 这是我上次试的 dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP") dim bStrm: Set bStrm = createobject("Adodb.Stream") xHttp.Open "GET", "" &Session("ServerURL") & "/idautomati

我试图让用户选择下载和保存一个网页到任何他们想要的地方。我一直在寻找解决办法,但似乎没有任何效果。我在经典asp中使用vbscript

这是我上次试的

dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "" &Session("ServerURL") & "/idautomation/IDAutomationStreamingLinear.aspx?D=MAPS$"&request.QueryString("catcode")&"%25"&request.QueryString("typecode")&"&X=0.09&BH=3&S=0&CC=T&LM=5&TM=7.5&ST=F", False
xHttp.Send

with bStrm
    .type = 1 '//binary
    .open
    .write xHttp.responseBody
    .savetofile "d:\DownloladPdf.pdf", 2 '//overwrite
end with
但它会在.savetofile行上抛出一个“写入文件失败”


我希望用户能够选择将其保存到何处…

您不能直接从服务器端代码VBscript保存到用户计算机,因为这将是一个主要的安全问题,允许人们浏览网页时驾车通过。它抛出错误的原因可能是它试图将其保存到服务器端,但服务器上没有D:

相反,您希望使用响应将PDF提供给浏览器,并让浏览器显示或保存PDF

下面的示例使用字节数组而不是流,但应该类似。如果要强制下载而不是在浏览器中显示,请将内容配置更改为“附件”。您还可以将文件名更改为您喜欢的任何文件名

if Len(pdfBytes) > 0 then
    Response.Clear()
    Response.ContentType = "application/pdf"
    Response.Charset = ""
    Response.AddHeader "Cache-Control", "public, max-age=1" ' Setting Cache-Control to max-age=1 rather than no-cache due to IE8 bug
    Response.AddHeader "content-disposition","inline; filename=filename.pdf"
    Response.Buffer = True
    Response.Expires = 0
    Response.BinaryWrite(pdfBytes)
    Response.Flush
    Response.End
    Response.Close
end if

显示您尝试过的代码。这不是家庭作业解决服务我编辑了我的问题上面链接的可能副本有一个答案,其中有一个如何使用流的示例。