zoukankan      html  css  js  c++  java
  • webclient 根据链接地址登陆后获取文件

    public static string DownloadFile(string strSourceUrl, string strDestFolder, string strUserName, string strPassword, string strDomain)
    {
    try
    {
    WebClient webclient = CreateWebClient(strUserName, strPassword, strDomain);

    // 下载
    Byte[] filecontents = webclient.DownloadData(strSourceUrl);

    string strFileName = Path.GetFileName(strSourceUrl);

    // 创建文件
    FileStream fs = new FileStream(strDestFolder + strFileName, FileMode.Create, FileAccess.Write);
    // 写文件
    fs.Write(filecontents, 0, filecontents.Length);

    fs.Close();
    return strFileName;
    }
    catch (Exception ex)
    {

    }

    return null;
    }

    // 创建WebClient
    // 参数:用户名,密码,域(用来登陆SharePoint)
    private static WebClient CreateWebClient(string strUserName, string strPassword, string strDomain)
    {
    WebClient webclient = new WebClient();

    if (String.IsNullOrEmpty(strUserName))
    {
    webclient.UseDefaultCredentials = true;
    }
    else
    {
    NetworkCredential credential = new NetworkCredential(strUserName, strPassword, strDomain);
    webclient.Credentials = credential;
    }
    return webclient;
    }

    为记录,方便查阅

  • 相关阅读:
    恐怖如斯
    java在vscode中配置环境的坑
    python的迭代器模块
    一个模仿输入print就有这么多知识点
    30个python常用小技巧
    第一个只出现一次的字符
    UIScrollView属性
    iOS 中UISlider常用知识点
    iOS中UISegmentedControl常用属性
    iOS触摸事件
  • 原文地址:https://www.cnblogs.com/liubinurl/p/4971133.html
Copyright © 2011-2022 走看看