2015-11-23 101 views
1

我试图让用户选择下载并保存网页到他们想要的位置。我一直在寻找解决方案,但似乎没有任何工作。我在经典的asp中使用vbscript。使用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线。

我希望用户能够选择在哪里保存它...

+0

显示您尝试过的代码。这不是作业解决服务 – mumair

+0

我编辑我的问题 – programmingGirl

+0

可能的重复[如何使用vbscript中的经典asp下载文件](http://stackoverflow.com/questions/12929866/how-to-download-the-files-使用-vbscript-in-classic-asp) – Dijkgraaf

回答

0

您不能保存从服务器端代码VBScript中的用户计算机直接,因为这将是一个重大的安全问题,使驱动器通过人们浏览网页的妥协。它可能导致错误的原因是它试图保存它在服务器端,但服务器上没有D :.

相反,您希望使用Response将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