Boas Enkler
Boas Enkler

Reputation: 12557

SlackApi - Missing Linebreaks

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);
            }

Upvotes: 3

Views: 2792

Answers (1)

Robert Levy
Robert Levy

Reputation: 29073

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.

Upvotes: 5

Related Questions