I have to POST Json data with cyrillic's symbols strings, like this:
string json = { "message": "Привет" }
I guess that I need to send something like this:
string json = { "message": "\u041F\u0440\u0438\u0432\u0435\u0442" }
So I tried to escape non-ascii encoded characters:
string privet = "\\u041F\\u0440\\u0438\\u0432\\u0435\\u0442";
But the server does not accept this, because string is passing as it is, with double backslashes:
string json = { "message": "\\u041F\\u0440\\u0438\\u0432\\u0435\\u0442" }
UTF-8 encoding not accepted too:
byte[] bJson = Encoding.UTF8.GetBytes(json);
How to get string in required format?
UPDATE
public class Test
{
public string message { get; set; }
}
Test myTest = new Test{ };
myTest.message = "\\u041F\\u0440\\u0438\\u0432\\u0435\\u0442";
string json = JsonConvert.SerializeObject(myTest, Formatting.Indented);
byte[] sbBites = Encoding.ASCII.GetBytes(json);
Uri url = new Uri("https://example.net");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = sbBites.Length;
request.ContentType = "application/json";
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(sbBites, 0, sbBites.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();