웹페이지에서 보안이나 기타이유로 URL 파라미터를 Get 전송방식을 막아놓을 때가 있다.
그래서 Post 방식으로 정보를 전달 할 때 아래와 같이 간단하게 구현 가능하다.
using System.Net;
using System.Collections.Specialized;
// Web Client Class의 UploadValues Method 이용
WebClient = client = new WebClient();
string url = "http://.......";
NameValueCollection params = new NameValueCollection
{
{ "PARAMETER_NAME_1", "PARAMETER_VALUE_1"},
{ "PARAMETER_NAME_2", "PARAMETER_VALUE_2"},
{ "PARAMETER_NAME_3", "PARAMETER_VALUE_3"}
};
byte[] response = client.UploadValues(url, params);
Console.WriteLine(Encoding.UTF8.GetString(response));
// 활용안
public static byte[] Post(string uri, NameValueCollection pairs)
{
byte[] response = null;
using (WebClient client = new WebClient())
{
try
{
response = client.UploadValues(uri, pairs);
}
catch(WebException ex)
{
Console.WriteLine("ERROR [ {0} ] => {1}", uri, ex.Message);
}
}
return response;
}











