JsonObjectCollection obj = new JsonObjectCollection();
obj.Add(new JsonStringValue("apiKey", 4F34GD33A3DH5));
obj.Add(new JsonStringValue("maker", "11681948"));
obj.Add(new JsonStringValue("receiver", "11619948"));
String sEntity = obj.ToString();
String sResult = SendHTTP(sEntity );
private String SendHTTP(string sEntity)
{
int nStartTime = 0;
string result = "";
string strMsg = string.Empty;
nStartTime = Environment.TickCount;
string urlString = "보낼 url주소";
HttpWebRequest request = null;
HttpWebResponse response = null;
try
{
Uri url = new Uri(urlString);
request = (HttpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Post;
request.Timeout = 5000;
// 인코딩1 - UTF-8
byte[] data = Encoding.UTF8.GetBytes(sEntity);
request.ContentType = "application/json";
request.ContentLength = data.Length;
// 데이터 전송
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();
// 전송응답
response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
result = streamReader.ReadToEnd();
// 연결닫기
streamReader.Close();
responseStream.Close();
response.Close();
}
catch (Exception ex)
{
return result;
}
return result;
}
Receive Thread 데이터 처리 및 이벤트 생성 (0) | 2017.09.20 |
---|---|
C# JSON 형식으로 전송 데이터 만들기 (0) | 2017.09.20 |
String.Format 을 이용한 문자정렬 왼쪽 오른쪽 가운데 (0) | 2017.07.19 |
C# 웹서비스로 JSON 결과값 생성하기 (0) | 2017.05.23 |
Log4Net (0) | 2017.05.23 |