我正在尝试用Web客户端加速上传文件的过程,我已经写了一些代码,运行良好,但非常慢,如果我尝试直接从网站上传相同的文件,它将花费更少的时间,有什么建议吗?或者其他我应该使用的库?
static string CreateDownloadLink(string File)
{
string ReturnValue = string.Empty;
try
{
using (WebClient Client = new WebClient())
{
byte[] Response = Client.UploadFile("https://anonfile.com/api/upload", File);
string ResponseBody = Encoding.ASCII.GetString(Response);
if (ResponseBody.Contains("\"error\": {"))
{
ReturnValue += "There was a erorr while uploading the file.\r\n";
ReturnValue += "Error message: " + ResponseBody.Split('"')[7] + "\r\n";
}
else
{
ReturnValue += "Download link: " + ResponseBody.Split('"')[15] + "\r\n";
ReturnValue += "File name: " + ResponseBody.Split('"')[25] + "\r\n";
}
}
}
catch (Exception Exception)
{
ReturnValue += "Exception Message:\r\n" + Exception.Message + "\r\n";
}
return ReturnValue;
}
发布于 2019-04-21 21:06:33
你可以使用HttpWebRequest类从内存上传。这看起来是一种更快的方法。
https://stackoverflow.com/questions/55782757
复制相似问题