c# POST
-
[C#] HttpWebRequest Class 활용한 Post 전송2014.02.13
[C#] HttpWebRequest Class 활용한 Post 전송
2014. 2. 13. 12:43
반응형
C#에서 http 프로토콜을 이용한 인터페이스.
protected void HttpCall()
{
String callUrl = "http://localhost:8080/test/call";
String[] data = new String[1];
data[0] = "nikemodel"; // id
data[1] = "password"; // pw
String postData = String.Format("id=&pw=", data[0], data[1]);
HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(callUrl);
//인코딩 UTF-8
byte[] sendData = UTF8Encoding.UTF8.GetBytes(postData);
httpWebRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = sendData.Length;
Stream requestStream = httpWebRequest.GetRequestStream();
requestStream.Write(sendData, 0, sendData.Length);
requestStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse) httpWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
String response = streamReader.ReadToEnd();
streamReader.Close();
httpWebResponse.Close();
console.Write("response : " + response);
}
반응형
'Programming > C#' 카테고리의 다른 글
[C#] short url 생성(bit.ly) (0) | 2014.02.13 |
---|---|
[C#] Win7 x64 IIS에서 32bit 응용 프로그램 사용 (0) | 2014.02.13 |
[C#] 중첩 리피터(Nested Repeater) 부모값 호출 하기 (0) | 2014.02.13 |
[C#] Generic 이란. (0) | 2014.01.07 |