I would've thought the streamWriter.Flush(); and streamWriter.Close(); is not necessary as you are inside a using block. At the end of the using block, stream writer will close anyway.
– RuchiraJan 19 '16 at 0:04

@user3772108 See stackoverflow.com/a/16380064/2279059. Use a JSON library, such as Newtonsoft JSON.Net, and render the JSON string from an object, or use serialization. I understand that this was omitted here for simplicity (although the simplicity gain is minimal), but formatting structured data strings (JSON, XML, ...) is too dangerous to do it even in trivial scenarios and to encourage people to copy such code.
– Florian WinterOct 25 '17 at 8:37

Further to Sean's post, it isn't necessary to nest the using statements. By using the StreamWriter it will be flushed and closed at the end of the block so no need to explicitly call the Flush() and Close() methods:

A little note on HttpClient, the general consensus is that you should not dispose it. Even it implements IDisposable the object is Thread-Safe and meant to be reused. stackoverflow.com/questions/15705092/…
– Jean F.Nov 14 '18 at 23:07

@JeanF. Hey Thanks for the input. As I have allready noted you should only create one instance or use the HttpClientFactory. I did not read all answers in the linked issue but I think it needs updating as it doesn't mention the factory.
– NtFreXNov 15 '18 at 8:03

Thanks for posting this solution Vivek. In our scenario we tried another solution in this post, and wound up seeing System.Threading exceptions in our application, due to what I assume were synchronous posts blocking threads. Your code solved our problem.
– Ken PalmerNov 22 '16 at 16:02

I recently came up with a much simpler way to post a JSON, with the additional step of converting from a model in my app. Note that you have to make the model [JsonObject] for your controller to get the values and do the conversion.