/*
url = http://10.0.0.1 웹서버 주소
lblUrl.Text = { "key1":"value1", "key2":"value2", "key3":"value3" } JSON 문자열
*/
// JSON POST (정보 전달)
private void JPOST()
{
try
{
// JSON 데이터 전송
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/json";
request.Method = "POST";
using (StreamWriter stream = new StreamWriter(request.GetRequestStream()))
{
stream.Write(lblUrl.Text);
stream.Flush();
stream.Close();
}
// JSON 데이터 전송 결과 학인하기
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
lblResult.Text = reader.ReadToEnd();
}
}
catch (Exception ex)
{
lblResult.Text = ex.Message;
}
}
/*
lblGetUrl.Text = http://10.0.0.1/check?key1= 고정값
txtGetID.Text = value1 지정값
*/
// JSON GET (정보 확인)
private void JGet()
{
using (WebClient client = new WebClient())
{
client.Encoding = Encoding.UTF8;
// 결과값을 Json 문자열로 받아온다.
lblGetRs.Text = client.DownloadString(lblGetUrl.Text + txtGetID.Text);
}
}