Answer the question
In order to leave comments, you need to log in
How to properly translate .docx file for use in HttpWebRequest POST body?
I did it like this but the server returns an error:
using (FileStream fstream = File.OpenRead(dlg.FileName))
{
// преобразуем строку в байты
byte[] array = new byte[fstream.Length];
// считываем данные
fstream.Read(array, 0, array.Length);
// декодируем байты в строку
content += System.Text.Encoding.Unicode.GetString(array);
}
...
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL_F);
request.Method = "POST";
string jsonContent = "{\u0022branch\u0022:\u0022master\u0022, \u0022author_name\u0022:\u0022Sergey\u0022, \u0022content\u0022:\u0022" + content + "\u0022,\u0022commit_message\u0022:\u0022My commit\u0022}";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(jsonContent);
request.ContentLength = byteArray.Length;
request.ContentType = @"application/json";
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
long length = 0;
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
length = response.ContentLength;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question