English 中文(简体)
从网站下载PDF内容——
原标题:Downloading PDF content from a website -
  • 时间:2011-04-30 19:56:58
  •  标签:
  • c#

我试图把国防军下载到我的台桌上——人民抵抗力量每几天都更新新内容,我正试图看到,如果人民抵抗力量有新内容,而不必与实际联系,那么它是否能够自动更新自己。

www.uakron.edu/dotAsset/1265971.pdf

问题回答

假设这个议题是,哪怕是遥远的方案拟定问题,你可以尝试一个吉大港定居人士协会的询问(在你的要求下,先寄出一名如果经过更新的客户的负责人),并检查回复负责人——如果服务器是友好的,则该服务器会告诉你它是否通过304份回复守则更新过。

如果您没有获得304份答复,那么就发出GET申请,并节省答复。

你还可以尝试以最后修改的方式(利用欧洲复兴开发银行)颁发全球升温潜能值证书,但如果服务器只对全球升温潜能值/304德国升温潜能值表示完全满意的话,欧洲复兴开发银行的请求可能节省一些带宽。

Not tested extensively, but:

using System;
using System.IO;
using System.Net;

static class Program
{
    static void Main()
    {
        string url = "http://www.uakron.edu/dotAsset/1265971.pdf", localPath = "1265971.pdf";

        var req = (HttpWebRequest)WebRequest.Create(url);
        req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
        req.Headers.Add("Accept-Encoding","gzip,deflate");
        if(File.Exists(localPath))
            req.IfModifiedSince = File.GetLastWriteTimeUtc(localPath);
        try
        {
            using (var resp = req.GetResponse())
            {
                int len;
                checked
                {
                    len = (int)resp.ContentLength;
                }
                using (var file = File.Create(localPath))
                using (var data = resp.GetResponseStream())
                {
                    byte[] buffer = new byte[4 * 1024];
                    int bytesRead;
                    while (len > 0 && (bytesRead = data.Read(buffer, 0, Math.Min(len, buffer.Length))) > 0)
                    {
                        len -= bytesRead;
                        file.Write(buffer, 0, bytesRead);
                    }
                }
            }
            Console.WriteLine("New version downloaded");
        }
        catch (WebException ex)
        {
            if (ex.Response == null || ex.Status != WebExceptionStatus.ProtocolError)
                throw;
            Console.WriteLine("Not updated");
        }
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签