百度不到找谷歌
用POST multipart/form-data 之类的关键字,翻了好一轮百度,本想着中文博客阅读随意马虎省点韶光,抄回来的代码都不能用,末了倒贴了不少无用功的韶光,没找到答案。
至心想办理问题,不google一下,还真的弗成,许多非专业开拓者可能还不知道若何上google,有这方面需求,可私信笔者,笔者可以给一点点指引。

在google上,很随意马虎翻到答案,终极找到了最优解,用RestSharp来办理,同时附上找到的一些不错的链接,供大家深入去学习下。
https://csharp.hotexamples.com/examples/RestSharp/RestRequest/AddFile/php-restrequest-addfile-method-examples.html
https://briangrinstead.com/blog/multipart-form-post-in-c/
https://github.com/jptoto/MultipartFormPoster
https://stackoverflow.com/questions/19954287/how-to-upload-file-to-server-with-http-post-multipart-form-data
项目利用.net 4.5的话,可以用HttpClient类库,貌似实现出来也比较随意马虎,但作为桌面端运用,哀求.net 4.5有点高,只能找.net 4.0下的RestSharp方案了(在nuget上要利用105版本才可以支持,最新的也不支持.net 4.0)。
说了这么久,该上代码的时候了。
API参数哀求
代码如下:
···
private static string GetUploadedPictureInfo(string filePath)
{ string url = \"大众https://sm.ms/api/upload\"大众; var client = new RestClient(url); client.Timeout = 3000; var request = new RestRequest(Method.POST); request.AddFile(\"大众smfile\公众, File.ReadAllBytes(filePath), Path.GetFileName(filePath)); request.AlwaysMultipartFormData = true; request.AddParameter(\公众ssl\公众, \"大众true\"大众, ParameterType.GetOrPost); var result = client.Execute(request); if (result.StatusCode == System.Net.HttpStatusCode.OK) { return result.Content; } else { return string.Empty; } }
···