
응답 데이터를 출력할 텍스트 박스와 클릭시 서버에게 일시 데이터를 요청할 버튼을 생성
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Http;
namespace restApiClient
{
public partial class Form1 : Form
{
private static HttpClient client;
public Form1()
{
InitializeComponent();
}
private void btnGetNow_Click(object sender, EventArgs e)
{
if(client == null)
{
client = new HttpClient();
}
HttpResponseMessage response = client.GetAsync("http://127.0.0.1:8080/api/now").GetAwaiter().GetResult();
string result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
textBox1.Text = result;
client = null;
}
}
}


now 버튼을 누르자 현재 일시가 텍스트로 출력된다