aspx文件无法打开

aspx文件无法打开

本文介绍了Webclient.DownloadFile().aspx文件无法打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用Powershell.我已经学会了如何使用以下代码使用网络客户端下载文件.

I'm using powershell for the first time. I've learned how to download files using a webclient, using the following code.

$client = New-Object System.NET.Webclient
$client.DownloadFile( $url, $path )

对于我最终想要做的事情来说,这似乎工作得很好,那就是一次从一个网页上下载多个文件.我在一个网站上尝试了该网站,该网站的文件格式设置为.pfva文件,并以PDF格式打开.没问题.这也是一个受密码保护的网站.

This seems to work nicely for what I am trying to eventually do, which is download multiple files from a web page at one time. I tried this on a site, which has its files formatted as .pfva files, which are opened as a PDF. no problem. This was a password protected site too.

因此,转到我实际上想在其上使用的网站.同样,该站点需要登录,尽管我只是在浏览器上登录然后运行Webclient.可能是为什么我从不需要在命令脚本中通过身份验证....

So moving to the site that I actually want to use it on. Again, a site requiring a log in, although I just sign in on my browser and then run the webclient. Probably why I never have to pass authentication in the command script....

此站点的文件格式为.aspx文件.它们将以PDF文件形式打开.我只需单击该文件,然后保存或打开,它自然就可以作为PDF文件工作.但是当我使用webclient.download文件时,它会下载到正确的位置...但是尝试打开它时出现错误.

This site's files are formatted as .aspx files. They are to be opened as PDF files. I can simply click on the file, save or open, and it works naturally as a PDF file. But when I use the webclient.download file, it downloads to the right spot...but I get an error when trying to open it.

"Adob​​e无法打开文件.文件编码不正确" ...类似这些内容.我上班了,现在无法收到消息.下载的网址采用以下格式:.....

"Adobe can't open file. It was not coded properly" ...something along those lines. I can't get the message up now because I'm at work. The URL for the downloads are in the following format.....

https://www.WebsiteABC.com/ShowDocument.aspx?DocPath=%7e%5cDocument%5cb75c6093-697a-4e59-bc26-fa2eb24f57f7%5cAUTHORIZATION.PDF

为什么不打开!!!有没有解决的办法.任何帮助,将不胜感激.谢谢!.

Why won't it open!?! Is there a way around this. Any help would be appreciated. Thank you!.

哦,顺便说一句,我将$ path设置为计算机目录中的.PDF文件...因为我读到应该提供文件路径,而不仅仅是目录.

OH btw, I set the $path to a .PDF file in a directory on my computer...because I read that a path to a file should be provided, and not just a directory.

推荐答案

在大多数情况下,您的脚本看起来可以正常工作.

Looks like your script works in the most of cases.

我发现页面,告诉用户代理HTTP标头字段对于服务器很重要,因此请尝试以下操作:

I found this page, telling that user agent HTTP header field can be important for server, so try this one:

$userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;)"
$url = "https://www.adobe.com/enterprise/pdfs/pdfarchiving.pdf"
$path = "c:\test.pdf"

$client = New-Object System.NET.Webclient
$client.Headers.Add("user-agent", $userAgent)
$client.DownloadFile( $url, $path )

这篇关于Webclient.DownloadFile().aspx文件无法打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 15:44