Getting 400 Bad Request when updating channel status

The Content-Length is automatically set when I set the request stream for the WebRequest object. However! That led me to the problem: the stream I was writing out wasn’t using the correct encoding. :smile: Once I changed it to use UTF8Encoding, it worked perfectly!

For those who are curious as to what the correct way is to set the request stream, here you go:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
string postData = "{\"channel\":{\"status\":"test channel status\",\"game\":\"Minecraft\"}}";
// Set headers, method here
UTF8Encoding encoding = new UTF8Encoding();
byte[] utfBytes = encoding.GetBytes(postData);
using (Stream dataStream = request.GetRequestStream())
{
	dataStream.Write(utfBytes, 0, utfBytes.Length);
}
// Send the request!