fix a bug

This commit is contained in:
Michael 2017-05-25 15:32:38 -04:00
parent de6d1d15ab
commit d40c527da1

View file

@ -121,36 +121,32 @@ internal static void ScreamToDiscord(string title, string desc, string url)
{
if (!string.IsNullOrWhiteSpace(conf.WebhookUrl))
{
var wc = HttpWebRequest.Create(conf.WebhookUrl);
wc.Method = "POST";
wc.ContentType = "application/json";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(conf.WebhookUrl);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(new
{
content = $@"**{title}**
{desc}
Visit this URL to see more: {url}"
Visit this URL for more info: {url}"
});
wc.ContentLength = json.Length;
using (var s = wc.GetRequestStream())
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
using(var writer = new StreamWriter(s))
{
writer.Write(json);
using(var r = wc.GetResponse())
{
using(var rs = r.GetResponseStream())
{
using(var reader = new StreamReader(rs))
{
string result = reader.ReadToEnd();
db.AuditLogs.Add(new AuditLog("system", AuditLogLevel.Admin, "Discord webhook sent. Result: " + result));
}
}
}
}
}
var result = streamReader.ReadToEnd();
}
}
}
}