Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Net.Http;
- namespace Smartcard.Controller
- {
- public class LoginController
- {
- private static readonly HttpClient client = new HttpClient();
- //request get http
- public async void requestGetHttp()
- {
- var response = await client.GetAsync("https://jsonplaceholder.typicode.com/posts");
- var responseString = await response.Content.ReadAsStringAsync();
- Console.WriteLine(responseString);
- }
- //request post http
- public async void requestPostHttp()
- {
- var values = new Dictionary<string, string>
- {
- { "thing1", "hello" },
- { "thing2", "world" }
- };
- var content = new FormUrlEncodedContent(values);
- try
- {
- var response = await client.PostAsync("https://jsonplaceholder.typicode.com/posts", content);
- var responseString = await response.Content.ReadAsStringAsync();
- Console.WriteLine(responseString);
- } catch (HttpRequestException e) {
- MessageBox.Show("No internet","แจ้งเตือน");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment