C#模拟POST上传文件帮助类(支持https、http)
public static int PostFile(string getUrl, CookieContainer cookieContainer, HttpHeader header, string postdata, byte[] postdatabyte, Stream sm) { Stream fileStream; if (sm != null) { fileStream = sm; } else { fileStream = new MemoryStream(postdatabyte); } ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls;//https形式需要添加 int returnValue = 0; fileStream.Position = 0; var r = new BinaryReader(fileStream); string strBoundary = "--"+ DateTime.Now.Ticks.ToString("x"); byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + strBoundary + "--\r\n"); //请求头部信息