class Program
{
static void Main(string[] args)
{
HttpWebRequest request = WebRequest.CreateHttp("********");
request.Method = WebRequestMethods.Http.Post;
var sp = Encoding.UTF8.GetBytes("-----------------------------7e33352f1074\r\n");
var end = Encoding.UTF8.GetBytes("\r\n-----------------------------7e33352f1074--");
request.ContentType = "multipart/form-data; boundary=---------------------------7e33352f1074";
var rq = request.GetRequestStream();
rq.Write(sp, 0, sp.Length);
var dataHeader = GetKeyValueHeader("name", "value");
rq.Write(dataHeader, 0, dataHeader.Length);
rq.Write(sp, 0, sp.Length);
var filePath = @"****";
dataHeader = GetFileHeader("file", filePath);
rq.Write(dataHeader, 0, dataHeader.Length);
var fileData = File.ReadAllBytes(filePath);
rq.Write(fileData, 0, fileData.Length);
rq.Write(end, 0, end.Length);
rq.Close();
var rs = request.GetResponse();
}
private static byte[] GetKeyValueHeader(string name, string value)
{
string str = $"Content-Disposition: form-data; name=\"{name}\"\r\n\r\n{value}\r\n";
return Encoding.UTF8.GetBytes(str);
}
private static byte[] GetFileHeader(string name, string fileName)
{
string str = $"Content-Disposition: form-data; name=\"{name}\"; filename=\"{fileName}\"\r\n" +
"Content-Type: application/octet-stream\r\n\r\n";
return Encoding.UTF8.GetBytes(str);
}
}