Revision | 116 (tree) |
---|---|
Zeit | 2020-08-14 14:28:38 |
Autor | ![]() |
* Slack通知はformではなくjsonで送るように変更
@@ -91,15 +91,9 @@ | ||
91 | 91 | var subject = string.Format("[{0}] {1}", data.HostName, GetSubject(data.Message)); |
92 | 92 | if (!Util.IsNullOrEmpty(data.Name)) |
93 | 93 | subject = string.Format("[{0}]{1}", data.Name, subject); |
94 | - Send(string.Concat("payload=", Encode(GetJSON(subject, text.ToString())))); | |
94 | + Send(GetJSON(subject, text.ToString())); | |
95 | 95 | } |
96 | 96 | |
97 | - private string Encode(string value) | |
98 | - { | |
99 | - var result = WebUtility.UrlEncode(value); | |
100 | - return result.Replace("+", "%20"); | |
101 | - } | |
102 | - | |
103 | 97 | private string GetSubject(string value) |
104 | 98 | { |
105 | 99 | if (!string.IsNullOrEmpty(value)) { |
@@ -140,12 +134,12 @@ | ||
140 | 134 | return jo.ToString(); |
141 | 135 | } |
142 | 136 | |
143 | - private string Send(string postData) | |
137 | + private string Send(string payload) | |
144 | 138 | { |
145 | - var data = Encoding.ASCII.GetBytes(postData); | |
139 | + var data = Encoding.UTF8.GetBytes(payload); | |
146 | 140 | var req = (HttpWebRequest)WebRequest.Create(URL); |
147 | 141 | req.Method = "POST"; |
148 | - req.ContentType = "application/x-www-form-urlencoded"; | |
142 | + req.ContentType = "application/json;charset=UTF-8"; | |
149 | 143 | req.ContentLength = data.Length; |
150 | 144 | |
151 | 145 | using (Stream s = req.GetRequestStream()) { |