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;
}