I'm sending data to a slack channel with webhook integration. But when i include a linebreak (\n) i get at http 500. When I url encode the linebreak i see the encoded value, not a real line break in slacn
string body = "foo"
if(!string.IsNullOrWhiteSpace(feedEntry.Link ))
{
body += " \n <" + feedEntry.Link +">";
}
body = "{\"text\": \"" + body+ "\"}";
using(var client = new HttpClient())
{
var msg = new StringContent(body);
var result = await client.PostAsync(url, msg);
}
Use \\n instead of \n. The string will then contain \ followed by n which is valid JSON and will turn into a newline char by the JSON parser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With