Skip to content

Instantly share code, notes, and snippets.

@KristofferRisa
Created March 28, 2016 13:24
Show Gist options
  • Save KristofferRisa/cd0323e7118f13e9bba7 to your computer and use it in GitHub Desktop.
Save KristofferRisa/cd0323e7118f13e9bba7 to your computer and use it in GitHub Desktop.
HTTP request in .Net using HttpClient
using System.Net.Http;
using (var client = new HttpClient())
{
var responseString = client.GetStringAsync("http://www.example.com/recepticle.aspx");
}
using System.Net.Http;
using (var client = new HttpClient())
{
var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
var responseString = await response.Content.ReadAsStringAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment