// Параметры: server - сервер для отправки запроса // service - ссылка на сервис сервера // fileWithJSON - путь к файлу с телом запроса // Туда же и поместится ответ сервера // timeout - время ожидания ответа от сервера public static void SendQuery(string server, string service, string fileWithJSON, int timeout) { try { string json = System.IO.File.ReadAllText(fileWithJSON); byte[] body = Encoding.UTF8.GetBytes(json); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://" + server + service); request.Timeout = timeout; request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = body.Length; using (Stream stream = request.GetRequestStream()) { stream.Write(body, 0, body.Length); stream.Close(); } string answer = ""; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader stream = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { answer = stream.ReadToEnd(); } response.Close(); } string[] lines = { answer }; System.IO.File.WriteAllLines(fileWithJSON, lines); } catch (Exception ex) { string info = "[ERROR]: " + ex.Message; string[] lines = { info }; System.IO.File.WriteAllLines(fileWithJSON, lines); } }