zoukankan      html  css  js  c++  java
  • C# WinForm 通过URL取得服务器上的某图片文件到本地

    方法1示例代码:
    --------------

    string strImageURL = "http://192.168.0.1:88/VDirA/images/1.jpg";
    
    System.Net.WebClient webClient = new System.Net.WebClient();
    webClient.DownloadFile(strImageURL, @"D:\1.jpg"); 

    方法2示例代码:
    --------------

    string strImageURL = "http://192.168.0.1:88/VDirA/images/1.jpg";
    
    System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strImageURL);
    webRequest.Method = "GET";
    System.Net.HttpWebResponse webResponse = (System.Net.HttpWebResponse)webRequest.GetResponse();
    
    System.IO.Stream s = webResponse.GetResponseStream();
    
    List<byte> list = new List<byte>();
    while (true)
    {
        int data = s.ReadByte();
        if (data == -1)
            break;
        else
        {
            byte b = (byte)data;
            list.Add(b);
        }
    }
    byte[] bb = list.ToArray();
    System.IO.File.WriteAllBytes("C://1.jpg", bb);
    s.Close();
  • 相关阅读:
    python之面向对象
    python之异常处理
    python之函数的使用
    python之模块的使用
    python之循环语句
    python之文件操作
    初识Python
    python爬虫之request模块详解
    pikachu之文件上传
    pikachu靶场之暴力破解
  • 原文地址:https://www.cnblogs.com/maijin/p/2834233.html
Copyright © 2011-2022 走看看