Пробую загрузить изображение в ВК на полученный адрес и постоянно выдаёт Security Breach2
Подскажите что не так?
Пробывал уже 3 способа
byte[] pic = File.ReadAllBytes(path);
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://pu.vk.com/c63728/upload.php?act=do_add&mid=39497&aid=256&gid=15&hash=db35&rhash=355f6&swoad=1&api=1");
Stream _stream;
string _boundary = String.Format("--{0}", GetMD5());
string _templateFile = "--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n";
string _templateEnd = "--{0}--\r\n\r\n";
Request.Method = "POST";
Request.ContentType = String.Format("multipart/form-data; boundary={0}", _boundary);
_stream = Request.GetRequestStream();
string FilePath = "test.jpg";
string FileType = "application/octet-stream";
string Name = "file1";
byte[] contentFile = Encoding.UTF8.GetBytes(String.Format(_templateFile, _boundary, Name, FilePath, FileType));
_stream.Write(contentFile, 0, contentFile.Length);
_stream.Write(pic, 0, pic.Length);
byte[] _lineFeed = Encoding.UTF8.GetBytes("\r\n");
_stream.Write(_lineFeed, 0, _lineFeed.Length);
byte[] contentEnd = Encoding.UTF8.GetBytes(String.Format(_templateEnd, _boundary));
_stream.Write(contentEnd, 0, contentEnd.Length);
HttpWebResponse webResponse = (HttpWebResponse)Request.GetResponse();
StreamReader read = new StreamReader(webResponse.GetResponseStream());
return read.ReadToEnd();
MultipartFormDataContent content = new MultipartFormDataContent();
using (var streamContent = new StreamContent(File.OpenRead(path)))
{
streamContent.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("form-data");
streamContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("name", "contentFile"));
streamContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("filename", "\"" + path + "\""));
content.Add(streamContent);
}
HttpResponseMessage response = await client.PostAsync("https://pu.vk.com/c63728/upload.php?act=do_add&mid=39497&aid=256&gid=15&hash=db35&rhash=355f6&swoad=1&api=1", content);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
ulong sentBytes = 0;
ulong totalBytes = 0;
string messageTotalMBytes;
WebClient client = new WebClient();
using (var web_stream = client.OpenWrite("https://pu.vk.com/c63728/upload.php?act=do_add&mid=39497&aid=256&gid=15&hash=db35&rhash=355f6&swoad=1&api=1"))
{
byte[] buffer = new byte[4096];
totalBytes = (ulong)file_stream.Length;//узнаём размер файла
messageTotalMBytes = Math.Round((float)totalBytes / 1048576, 3) + " Мбайт";
//Читаем данные
int bytesRead = await file_stream.ReadAsync(buffer, 0, buffer.Length);
while (bytesRead > 0)
{
await web_stream.WriteAsync(buffer, 0, bytesRead);
sentBytes += (ulong)bytesRead;
progress.SetMessage("Отправлено: " + (int)(100 * (float)sentBytes / totalBytes) + " %\nиз " + messageTotalMBytes);
bytesRead = await file_stream.ReadAsync(buffer, 0, buffer.Length);
}
Console.WriteLine(sentBytes);
file_stream.Dispose();
file_stream.Close();
}