FTP文件上傳以及獲取ftp配置幫助類

来源:http://www.cnblogs.com/qinyi173/archive/2017/07/14/7169195.html
-Advertisement-
Play Games

幫助類: 配置文件配置: <!--ftp配置,以分號相隔 格式:"主機名;用戶名;密碼;"-->例子:<Item key="FtpConfig" value="192.168.0.1;admin;123456" /> 上傳調用例子: ...


幫助類:

using QSProjectBase;
using Reform.CommonLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace Reform.CommonLib
{
    /// <summary>
    /// ftp操作
    /// </summary>
    public class FtpHelper
    {
        /// <summary>
        /// 上傳文件
        /// </summary>
        /// <param name="fileName">上傳文件的全路徑</param>
        /// <param name="accessory">上傳類</param>
        /// <returns></returns>
        public static bool UploadFile(FileInfo fileinfo, string ftpPath)
        {
            try
            {
                if (fileinfo == null || string.IsNullOrEmpty(ftpPath))
                    return false;

                string url = ftpPath;
                if (url.Contains("/") || url.Contains("\\"))
                {
                    var str = url.Split(new Char[] { '/', '\\' });
                    var dic = url.Replace(str[str.Length - 1], "");
                    CheckAndMakeDir(dic);
                }

                System.Net.FtpWebRequest ftp = GetRequest(url);

                //設置FTP命令 設置所要執行的FTP命令,
                //ftp.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails;//假設此處為顯示指定路徑下的文件列表
                ftp.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
                ftp.UseBinary = true;
                ftp.UsePassive = true;
                ftp.ContentLength = fileinfo.Length;

                const int BufferSize = 20480; //緩衝大小設置為20KB
                byte[] content = new byte[BufferSize - 1 + 1];
                int dataRead;

                using (FileStream fs = fileinfo.OpenRead())
                {
                    try
                    {
                        using (Stream rs = ftp.GetRequestStream())
                        {
                            do
                            {
                                dataRead = fs.Read(content, 0, BufferSize);
                                rs.Write(content, 0, dataRead);
                            } while (!(dataRead < BufferSize));
                            rs.Close();
                        }
                    }
                    catch (Exception) { }
                    finally
                    {
                        fs.Close();
                    }
                }
                ftp = null;
                ////設置FTP命令
                //ftp = GetRequest(URI);
                //ftp.Method = System.Net.WebRequestMethods.Ftp.Rename; //改名
                //ftp.RenameTo = fileinfo.Name;
                //try
                //{
                //    ftp.GetResponse();
                //}
                //catch (Exception ex)
                //{
                //    ftp = GetRequest(URI);
                //    ftp.Method = System.Net.WebRequestMethods.Ftp.DeleteFile; //刪除
                //    ftp.GetResponse();
                //}
                //ftp = null;
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// 上傳文件
        /// </summary>
        /// <param name="fileName">上傳文件的全路徑</param>
        /// <param name="ftpPath">上傳的目錄(包括文件名)</param>
        /// <param name="progressHelper">進度幫助</param>
        /// <returns></returns>
        public static bool UploadFile(FileInfo fileinfo, string ftpPath, ProgressHelper progressHelper, MessageProgressHandler handler)
        {
            try
            {
                if (fileinfo == null || string.IsNullOrEmpty(ftpPath))
                    return false;

                string url = ftpPath;
                if (url.Contains("/") || url.Contains("\\"))
                {
                    var str = url.Split(new Char[] { '/', '\\' });
                    var dic = url.Replace(str[str.Length - 1], "");
                    CheckAndMakeDir(dic);
                }
                System.Net.FtpWebRequest ftp = GetRequest(url);

                //設置FTP命令 設置所要執行的FTP命令,
                //ftp.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails;//假設此處為顯示指定路徑下的文件列表
                ftp.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
                ftp.UseBinary = true;
                ftp.UsePassive = false;
                ftp.ContentLength = fileinfo.Length;

                const int BufferSize = 20480; //緩衝大小設置為20KB
                byte[] content = new byte[BufferSize - 1 + 1];
                int dataRead;


                using (FileStream fs = fileinfo.OpenRead())
                {
                    long fileLen = fs.Length;
                    if (progressHelper != null && handler != null)
                    {
                        progressHelper.SetProgress(handler, "正在上傳...", 0);
                    }
                    try
                    {
                        long proValue = 0;
                        using (Stream rs = ftp.GetRequestStream())
                        {

                            do
                            {
                                dataRead = fs.Read(content, 0, BufferSize);
                                rs.Write(content, 0, dataRead);
                                proValue += dataRead;
                                if (progressHelper != null && handler != null)
                                {
                                    progressHelper.SetProgress(handler, "正在上傳...", (int)((double)proValue * 100 / fileLen));
                                }
                            } while (!(dataRead < BufferSize));
                            var aa = rs.Length;
                            rs.Close();
                        }
                    }
                    catch (Exception) { }
                    finally
                    {
                        fs.Close();
                    }
                }
                ftp = null;
                ////設置FTP命令
                //ftp = GetRequest(URI);
                //ftp.Method = System.Net.WebRequestMethods.Ftp.Rename; //改名
                //ftp.RenameTo = fileinfo.Name;
                //try
                //{
                //    ftp.GetResponse();
                //}
                //catch (Exception ex)
                //{
                //    ftp = GetRequest(URI);
                //    ftp.Method = System.Net.WebRequestMethods.Ftp.DeleteFile; //刪除
                //    ftp.GetResponse();
                //}
                //ftp = null;
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// 下載文件
        /// </summary>
        /// <param name="localDir">下載到本地(全路徑)</param>
        /// <param name="accessory">要下載的附件類</param> 
        public static bool DownloadFile(string localFilePath, string ftpPath)
        {
            if (string.IsNullOrEmpty(ftpPath)) return false;
            if (string.IsNullOrEmpty(localFilePath)) return false;
            System.Net.FtpWebRequest ftp = null;
            try
            {
                string Url = ftpPath;
                string localDir = new FileInfo(localFilePath).DirectoryName;
                if (!Directory.Exists(localDir))
                {
                    Directory.CreateDirectory(localDir);
                }
                string tmpname = Guid.NewGuid().ToString();
                string tmpFilePath = localDir + @"\" + tmpname;

                ftp = GetRequest(Url);
                // MsgBoxShow.ShowInformation(Url);
                ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile;
                ftp.UseBinary = true;
                ftp.UsePassive = false;

                using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        using (FileStream fs = new FileStream(tmpFilePath, FileMode.CreateNew))
                        {
                            var aa = ftp.ContentLength;
                            try
                            {
                                byte[] buffer = new byte[20480];
                                int read = 0;
                                do
                                {
                                    read = responseStream.Read(buffer, 0, buffer.Length);
                                    fs.Write(buffer, 0, read);
                                } while (!(read == 0));
                                responseStream.Close();
                                fs.Flush();
                                fs.Close();
                            }
                            catch (Exception)
                            {
                                fs.Close();
                                File.Delete(tmpFilePath);
                                return false;
                            }
                        }
                        responseStream.Close();
                    }
                    response.Close();
                }
                try
                {
                    File.Delete(localFilePath);
                    File.Move(tmpFilePath, localFilePath);
                    ftp = null;
                }
                catch (Exception)
                {
                    File.Delete(tmpFilePath);
                    return false;
                }
                ftp = null;
                return true;
            }
            catch (WebException e)
            {
                Common_LogManager.RecordLog(LogType.Error, e.Message, e);
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    Console.WriteLine("Status Code : {0}", ((FtpWebResponse)e.Response).StatusCode);
                    Console.WriteLine("Status Description : {0}", ((FtpWebResponse)e.Response).StatusDescription);
                }
                return false;
            }
        }

        /// <summary>
        /// 下載文件,疊加
        /// </summary>
        /// <param name="localDir">下載到本地(全路徑)</param>
        /// <param name="accessory">要下載的附件類</param> 
        public static bool DownloadFileEx(string localFilePath, string ftpPath)
        {
            if (string.IsNullOrEmpty(ftpPath)) return false;
            if (string.IsNullOrEmpty(localFilePath)) return false;
            try
            {
                string Url = ftpPath;

                System.Net.FtpWebRequest ftp = GetRequest(Url);
                ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile;
                ftp.UseBinary = true;
                ftp.UsePassive = false;

                using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        using (FileStream fs = new FileStream(localFilePath, FileMode.Append))
                        {
                            try
                            {
                                byte[] buffer = new byte[20480];
                                int read = 0;
                                do
                                {
                                    read = responseStream.Read(buffer, 0, buffer.Length);
                                    fs.Write(buffer, 0, read);
                                } while (!(read == 0));
                                responseStream.Close();
                                fs.Flush();
                                fs.Close();
                            }
                            catch (Exception)
                            {
                                fs.Close();
                                return false;
                            }
                        }
                        responseStream.Close();
                    }
                    response.Close();
                }
                try
                {
                    ftp = null;
                }
                catch (Exception)
                {
                    return false;
                }
                ftp = null;
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// 下載文件(包含進度)
        /// </summary>
        /// <param name="localDir">下載到本地(全路徑)</param>
        /// <param name="accessory">要下載的附件類</param> 
        public static bool DownloadFile(string localFilePath, string ftpPath, ProgressHelper progressHelper, MessageProgressHandler handler)
        {
            if (string.IsNullOrEmpty(ftpPath)) return false;
            if (string.IsNullOrEmpty(localFilePath)) return false;

            try
            {
                string URI = ftpPath;
                string localDir = new FileInfo(localFilePath).DirectoryName;

                string tmpname = Guid.NewGuid().ToString();
                string tmpFilePath = localDir + @"\" + tmpname;

                System.Net.FtpWebRequest ftp = GetRequest(URI);
                ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile;
                ftp.UseBinary = true;
                ftp.UsePassive = false;
                long fileLen = GetFileSize(ftpPath);
                using (WebResponse response = ftp.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        if (progressHelper != null && handler != null)
                        {
                            progressHelper.SetProgress(handler, "正在下載...", 0);
                        }
                        using (FileStream fs = new FileStream(tmpFilePath, FileMode.OpenOrCreate))
                        {
                            try
                            {
                                long proValue = 0;
                                byte[] buffer = new byte[20480];
                                int read = 0;
                                do
                                {
                                    read = responseStream.Read(buffer, 0, buffer.Length);
                                    fs.Write(buffer, 0, read);
                                    proValue += read;
                                    if (progressHelper != null && handler != null)
                                    {
                                        progressHelper.SetProgress(handler, "正在下載...", (int)((double)proValue * 100 / fileLen));
                                    }
                                } while (!(read == 0));
                                responseStream.Close();
                                fs.Flush();
                                fs.Close();
                            }
                            catch (Exception)
                            {
                                fs.Close();
                                File.Delete(tmpFilePath);
                                return false;
                            }
                        }
                        responseStream.Close();
                    }
                    response.Close();
                }
                try
                {
                    File.Delete(localFilePath);
                    File.Move(tmpFilePath, localFilePath);
                    ftp = null;
                }
                catch (Exception ex)
                {
                    File.Delete(tmpFilePath);
                    return false;
                }
                ftp = null;
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// 刪除文件
        /// </summary>
        /// <param name="accessory">要刪除的附件全路徑</param> 
        public static bool DeleteFile(string ftpPath)
        {
            if (string.IsNullOrEmpty(ftpPath)) return false;
            try
            {
                string URI = ftpPath;
                System.Net.FtpWebRequest ftp = GetRequest(URI);
                ftp.Method = System.Net.WebRequestMethods.Ftp.DeleteFile;
                ftp.UseBinary = true;
                ftp.UsePassive = false;
                using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        responseStream.Close();
                    }
                    response.Close();
                }
                ftp = null;
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }


        /// <summary>
        /// 搜索遠程文件
        /// </summary>
        /// <param name="targetDir">文件夾</param>  
        /// <param name="SearchPattern">搜索模式</param>
        /// <returns></returns>
        public static List<string> ListDirectory(string targetDir, string SearchPattern)
        {
            List<string> result = new List<string>();
            try
            {
                string URI = targetDir + "/" + SearchPattern;
                System.Net.FtpWebRequest ftp = GetRequest(URI);
                ftp.Method = System.Net.WebRequestMethods.Ftp.ListDirectory;
                ftp.UsePassive = true;
                ftp.UseBinary = true;


                string str = GetStringResponse(ftp);
                str = str.Replace("\r\n", "\r").TrimEnd('\r');
                str = str.Replace("\n", "\r");
                if (str != string.Empty)
                    result.AddRange(str.Split('\r'));

                return result;
            }
            catch { }
            return null;
        }

        private static string GetStringResponse(FtpWebRequest ftp)
        {
            string result = "";
            using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
            {
                long size = response.ContentLength;
                using (Stream datastream = response.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(datastream, System.Text.Encoding.Default))
                    {
                        result = sr.ReadToEnd();
                        sr.Close();
                    }

                    datastream.Close();
                }

                response.Close();
            }

            return result;
        }

        public static void CheckAndMakeDir(string dirName)
        {
            if (string.IsNullOrEmpty(dirName))
            {
                return;
            }
            if (dirName.Contains("/") || dirName.Contains("\\"))
            {
                var str = dirName.Split(new Char[] { '/', '\\' });
                if (str.Length == 0 || string.IsNullOrEmpty(str[0]))
                {
                    return;
                }
                string dir = str[0] + "/";
                if (!IsExistsFile(dir))
                    MakeDir(dir);
                for (int i = 1; i < str.Length; i++)
                {
                    if (string.IsNullOrEmpty(str[i]))
                    {
                        continue;
                    }
                    dir += (str[i] + "/");
                    if (!IsExistsFile(dir))
                        MakeDir(dir);
                }

            }
            else
            {
                if (!IsExistsFile(dirName))
                    MakeDir(dirName);
            }
        }
        ///
        /// 在ftp伺服器上創建目錄
        /// </summary>
        /// <param name="dirName">創建的目錄名稱</param> 
        public static void MakeDir(string dirName)
        {
            try
            {
                System.Net.FtpWebRequest ftp = GetRequest(dirName);
                ftp.Method = WebRequestMethods.Ftp.MakeDirectory;

                FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
                response.Close();
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
        }

        /// <summary>
        /// 刪除目錄
        /// </summary>
        /// <param name="dirName">刪除目錄名稱</param> 
        public static bool delDir(string dirName)
        {
            try
            {
                System.Net.FtpWebRequest ftp = GetRequest(dirName);
                ftp.Method = WebRequestMethods.Ftp.RemoveDirectory;
                FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
                response.Close();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        /// <summary>
        /// 文件重命名
        /// </summary>
        /// <param name="currentFilename">當前目錄名稱</param>
        /// <param name="newFilename">重命名目錄名稱</param> 
        public static bool Rename(string currentFilename, string newFilename)
        {
            try
            {
                FileInfo fileInf = new FileInfo(currentFilename);
                System.Net.FtpWebRequest ftp = GetRequest(fileInf.Name);
                ftp.Method = WebRequestMethods.Ftp.Rename;

                ftp.RenameTo = newFilename;
                FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();

                response.Close();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        private static FtpWebRequest GetRequest(string dirName)
        {
            string url = "ftp://" + ConfigHepler.FtpServer + "/" + dirName;
            //根據伺服器信息FtpWebRequest創建類的對象
            FtpWebRequest result = (FtpWebRequest)FtpWebRequest.Create(url);
            //提供身份驗證信息
            result.Credentials = new System.Net.NetworkCredential(ConfigHepler.FtpUser, ConfigHepler.FtpPwd);
            //設置請求完成之後是否保持到FTP伺服器的控制連接,預設值為true
            result.KeepAlive = false;

            return result;
        }

        /// <summary>
        /// 判斷ftp伺服器上該目錄是否存在
        /// </summary>
        /// <param name="dirName"></param> 
        /// <returns></returns>
        public static bool IsExistsFile(string dirName)
        {
            bool flag = true;
            try
            {
                System.Net.FtpWebRequest ftp = GetRequest(dirName);
                ftp.Method = WebRequestMethods.Ftp.ListDirectory;

                FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
                response.Close();
            }
            catch (Exception)
            {
                flag = false;
            }
            return flag;
        }

        // 獲取文件大小
        public static long GetFileSize(string ftpPath)
        {
            long size = 0;
            if (string.IsNullOrEmpty(ftpPath)) return size;
            try
            {
                string URI = ftpPath;


                System.Net.FtpWebRequest ftp = GetRequest(URI);
                ftp.Method = System.Net.WebRequestMethods.Ftp.GetFileSize;
                ftp.UseBinary = true;
                ftp.UsePassive = false;

                using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
                {

                    size = response.ContentLength;

                }

            }
            catch (Exception)
            {

            }
            return size;
        }



    }


    /// <summary>
    /// 從配置文件獲取配置信息
    /// </summary>
    public class ConfigHepler
    {
        private static string m_FtpServer;
        private static string m_FtpUser;
        private static string m_FtpPwd;
        /// <summary>
        /// ftp伺服器  
        /// </summary>
        public static string FtpServer
        {
            get
            {
                if (string.IsNullOrEmpty(m_FtpServer))
                {
                    string[] ftpConfigs = GlobalVars.FtpConfig.Split(new char[] { ';' });
                    if (ftpConfigs != null && ftpConfigs.Length > 0)
                        m_FtpServer = ftpConfigs[0];
                }

                return m_FtpServer;
            }
        }

        /// <summary>
        /// ftp用戶名
        /// </summary>
        public static string FtpUser
        {
            
              
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 上一篇博客學習瞭如何簡單的使用多線程。其實普通的多線程確實很簡單,但是一個安全的高效的多線程卻不那麼簡單。所以很多時候不正確的使用多線程反倒會影響程式的性能。 下麵先看一個例子 : 執行結果: 從上面可以看出變數 num 的值不是連續遞增的,輸出也是沒有順序的,而且每次輸出的值都是不一樣的,這是因為 ...
  • using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace ConsoleApp1{ class Program { ...
  • HTTP模擬工具 開發語言:C#/Winform開發工具:Visual Studio 2017資料庫: SQLite使用框架:界面-MetroModernUI Http請求-RestSharp ORM-Dapper.Net Json解析-Newtonsoft.Json 多線程-SmartThread ...
  • Adding a view to an ASP.NET Core MVC app 在asp.net core mvc中添加視圖 2017-3-4 7 分鐘閱讀時長 本文內容 1.Changing views and layout pages 修改視圖和佈局頁 2.Change the title a ...
  • 做好一個ASP.NET MVC網站,訪問速度非常慢,要幾秒到幾十秒不等的時間才能展現頁面.每隔幾十分鐘就會出現一次這樣的情況.下麵分享優化方法 開發環境是:VS2015 + IIS8+ SQL Server 部署環境是:Windows 2008 R2+ IIS7+ SQL Server 設置IIS回 ...
  • 如今無論是社交媒體平臺還是企業解決方案,Web services都不出不在。為了可以跨平臺使用,如何“暴露”你的APIs就顯得非常重要。當前,很多APIs錶面上聲稱是RESTful,但實際上它們是改進過後的RPC。 ...
  • 將別人開發的exe程式,放到自己的窗體裡面來運行。 1.基本功能實現 首先,在自己的窗體後面加上代碼: 然後在需要的地方,加上代碼: 即可: 【http://www.cnblogs.com/CUIT-DX037/】 ...
  • 上一文章,主要介紹Dockerfile里各參數的含義,以及在項目文件里這些內容的含義,因為大叔認為官方和網上其它文章說的有些模棱兩可,不太好讓大家理解,所有我又從新寫了一個大白話的文章,希望可以給大家一些幫助.<DotNetCore跨平臺~Dockerfile的解釋> 本文章主要對一個windows ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...