static void Main(string[] args) { CookieContainer cookieContainer = new CookieContainer(); using (HttpClient client = new HttpClient("http://localhost:44857/")) { HttpClientChannel clientChannel = new HttpClientChannel(); clientChannel.CookieContainer = cookieContainer; client.Channel = clientChannel; HttpContent loginData = new FormUrlEncodedContent( new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Username", "foo"), new KeyValuePair<string, string>("Password", "bar") } ); client.Post("login", loginData); } string result = string.Empty; using (HttpClient client = new HttpClient("http://localhost:44857/contact/")) { HttpClientChannel clientChannel = new HttpClientChannel(); clientChannel.CookieContainer = cookieContainer; client.Channel = clientChannel; client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.Get("1"); result = response.Content.ReadAsString(); } JavaScriptSerializer jsonDeserializer = new JavaScriptSerializer(); ContactDto contact = jsonDeserializer.Deserialize<ContactDto>(result); Console.WriteLine(contact.Name); Console.ReadLine(); }
public static HttpClient CreateDefault() { var clientChannel = new HttpClientChannel {AllowAutoRedirect = true}; var client = new HttpClient{ Channel = clientChannel}; client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(AtomMediaType.Value.MediaType)); return client; }
public static HttpClient Create(string subscriptionId, X509Certificate2 certificate) { var channel = new HttpClientChannel(); channel.ClientCertificates.Add(certificate); var client = new HttpClient(string.Format("https://management.core.windows.net/{0}/", subscriptionId)) { Channel = channel }; client.DefaultRequestHeaders.Add("x-ms-version", "2011-02-25"); return client; }
public MovieAgent(HttpClientChannel httpClientChannel) : base(httpClientChannel) { this.endPoint = ConfigurationManager.AppSettings["MovieEndPoint"]; }
public static HttpClient CreateWithChannel(HttpClientChannel endpoint) { var client = new HttpClient {Channel = endpoint}; client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(AtomMediaType.Value.MediaType)); return client; }