Here\'s the code I\'m using:
// create a request
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(url); request.KeepAlive = false;
request.Protoco
WARNING! I have a very strong view on this subject.
.NET’s existing web clients are not developer friendly! WebRequest & WebClient are prime examples of "how to frustrate a developer". They are verbose & complicated to work with; when all you want to do is a simple Post request in C#. HttpClient goes some way in addressing these issues, but it still falls short. On top of that Microsoft’s documentation is bad … really bad; unless you want to sift through pages and pages of technical blurb.
Open-source to the rescue. There are three excellent open-source, free NuGet libraries as alternatives. Thank goodness! These are all well supported, documented and yes, easy - correction…super easy - to work with.
There is not much between them, but I would give ServiceStack.Text the slight edge …
Ok - so what does a Post Request in JSON look like within ServiceStack.Text?
var response = "http://example.org/login"
.PostJsonToUrl(new Login { Username="admin", Password="mypassword" });
That is one line of code. Concise & easy! Compare the above to .NET’s Http libraries.