I'm trying to figure out how to use HttpClient
to POST
some simple parameters.
- Password
I've been doing this with RestSharp, but I'm trying to migrate off that.
How can I do this with HttpClient
, please?
I have the following RestSharp code
var restRequest = new RestRequest("account/authenticate", Method.POST);
restRequest.AddParameter("Email", email);
restRequest.AddParameter("Password", password);
How can I convert that to use the (Microsoft.Net.Http) HttpClient
class, instead?
Take note: I'm doing a POST
Also, this is with the PCL assembly.
Lastly, can I add in a custom header. Say: "ILikeTurtles", "true"
.
This code isn't using HttpClient but it's using the System.Net.WebClient class, i guess it does the same thing though.
If you're not opposed to using a library per se, as long as it's
HttpClient
under the hood, Flurl is another alternative. [disclaimer: I'm the author]This scenario would look like this:
This should do it