Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void HttpGetAll()
- {
- var client = new HttpClient();
- HttpResponseMessage response = client.Get(CONTACTS_URI);
- Console.WriteLine("GET: {0} RESPONSE: {1} \n{2}\n",
- CONTACTS_URI,
- response.StatusCode,
- response.Content.ReadAsString());
- //var contacts = response.Content.ReadAs<Contact[]>();
- //Console.WriteLine("STATICALLY TYPE CONTACTS COUNT: {0}\n", contacts.Length);
- }
- private static void HttpPost()
- {
- var client = new HttpClient();
- client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypes.JSON));
- HttpContent jsonContactNew = new StringContent("{\"Id\":0,\"Name\":\"Edward\"}", Encoding.UTF8, MediaTypes.JSON);
- HttpResponseMessage response = client.Post(CONTACTS_URI, jsonContactNew);
- Console.WriteLine("POST (INSERT CONTACT): {0} RESPONSE: {1} \n{2}\n",
- response.Headers.Location,
- response.StatusCode,
- response.Content.ReadAsString());
- }
- private static void HttpPut()
- {
- var client = new HttpClient();
- client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypes.JSON));
- HttpContent jsonContactUpdated = new StringContent("{\"Id\":2,\"Name\":\"Ziggy\"}", Encoding.UTF8, MediaTypes.JSON);
- HttpResponseMessage response = client.Put(CONTACTS_URI, jsonContactUpdated);
- Console.WriteLine("POST (UPDATE CONTACT ID 2): {0} RESPONSE: {1}\n",
- CONTACTS_URI,
- response.StatusCode);
- }
- private static void HttpDelete()
- {
- var client = new HttpClient();
- const string uri = CONTACTS_URI + "/3";
- HttpResponseMessage response = client.Delete(uri);
- Console.WriteLine("DELETE (CONTACT ID 3): {0} RESPONSE: {1} \n",
- uri,
- response.StatusCode);
- }
- private static void HttpGet()
- {
- var client = new HttpClient();
- const string uri = CONTACTS_URI + "/1";
- HttpResponseMessage response = client.Get(uri);
- Console.WriteLine("GET: {0} RESPONSE: {1} \n{2}\n",
- uri,
- response.StatusCode,
- response.Content.ReadAsString());
- //var contact = response.Content.ReadAs<Contact>();
- //Console.WriteLine("STATICALLY TYPE CONTACT: {0}\n", contact);
- }
Add Comment
Please, Sign In to add comment