就是验证码图片,怎么保存到本地,跪谢

解决方案 »

  1.   

    WebClient.DownloadFile
      

  2.   

     byte[] urlContents = client.GetByteArrayAsync(uri);
                    fs = new System.IO.FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\images\\" + i.ToString() + ".jpg", System.IO.FileMode.CreateNew);
                    fs.Write(urlContents, 0, urlContents.Length);
      

  3.   

    new System.Net.Http.HttpClient().PostAsync().Result.Content.ReadAsByteArrayAsync()
    给你举例,通过ReadAsByteArrayAsync获取所有的数据,然后通过File.WriteAllBytes写入本地文件
      

  4.   

    public void DownImage(string Url,string Path)  
       {  
           System.Net.WebClient web = new System.Net.WebClient();  
           web.DownloadFile(Url, Path);  
      
       }  
      

  5.   

    方法很多:
           以下示例代码.NET 2.0及以后版本都支持。
    mode 1
    ------------------------------------------------------
                WebClient webclient = new WebClient();
                string bstrFileName = string.Empty;
                string bstrUrlAddress = string.Empty;
                webclient.DownloadFile(bstrUrlAddress, bstrFileName);
    ---------------------
    mode 2
    ---------------------
                WebClient webclient = new WebClient();
                string bstrFileName = string.Empty;
                string bstrUrlAddress = string.Empty;
                File.WriteAllBytes(bstrFileName, webclient.DownloadData(bstrUrlAddress));
    ----------------------
    mode 3
    ---------------------
                WebClient webclient = new WebClient();
                string bstrFileName = string.Empty;
                string bstrUrlAddress = string.Empty;
                webclient.DownloadDataCompleted += (sender, e) =>
                {
                    if (!e.Cancelled && e.Error == null)
                    {
                        File.WriteAllBytes(bstrFileName, e.Result);
                    }
                };
                webclient.DownloadDataAsync(new Uri(bstrUrlAddress));
    ----------------------
    mode 4
    ... ... 
      

  6.   

           编写代码只要不是面向客户的,你可以应用高版本dotNET框架
    的特性 但一个好的建议是,你需要为工程假定一个绝对意义“运行时”
    version and C# lang version
    -----------------------------------------------------------------
    通用定义:dotNET FRA 4.0 + C# 4.0
    通用定义:dotNET FRA 2.0 + C# 2.0
    -----------------------------
           当你定义好了“运行库”的版本时,那么所有与此关联的开发人员
    必须强制性的禁止使用任何脱离“限定”的API及语法。
           注:不要使用到“dotNET”运行库中“obsolete”标注的成员。      不要试图向“云云大众”一般盲目的追求各种新的特性新的版本,
    为什么要这么做?      它将为你带来诸如“统一开发环境,易于工程维护,易于工程迁
    移,易于工程升级,减少语义混淆”等多个方面的好处。