C#从URL aspx下载PDF?

时间:2015-03-20 13:25:44

标签: c# pdf visual-studio-2013

我尝试了几种方法来下载在此(http://187.72.229.145/esiat/Valida_NFE_Emissao.aspx?InscricaoMunicipal=0032161&NumeroNota=15&CodVrfNfe=TWU7UO47QG)ASPX页面中生成的PDF,但却无法下载。

我尝试WebClient,WebRequest ..等等。 知道如何在c#e .net 3.5 ???

中做到这一点

例如:

private void button1_Click(object sender, EventArgs e)
    {
        string url = "http://187.72.229.145/esiat/Valida_NFE_Emissao.aspx?InscricaoMunicipal=0032161&NumeroNota=15&CodVrfNfe=TWU7UO47QG";
        string fileName = "pdf.pdf";
        WebClient webClient = new WebClient();
        webClient.DownloadFile(url, fileName);

    }

2 个答案:

答案 0 :(得分:0)

您可能需要使用代理,添加以下行:

webClient.Proxy = new WebProxy("192.168.1.5", 3128);  // <- Proxy address & port
webClient.DownloadFile(url, fileName);

最好使用文件名的绝对路径。

答案 1 :(得分:0)

我改变了WebClient的形状,它起作用了!

private void button1_Click(object sender, EventArgs e)
    {
        string url = "http://187.72.229.145/esiat/Valida_NFE_Emissao.aspx?InscricaoMunicipal=0032161&NumeroNota=15&CodVrfNfe=TWU7UO47QG";
        string fileName = "pdf.pdf";
        WebClient webClient = new WebClient();
        webClient.DownloadFileAsync(new Uri(url, UriKind.Absolute), fileName);
    }