Статья: Отправка запроса методом POST на сервер из .NET приложения

SomeBytes = Encoding.GetEncoding(1251).GetBytes("ParamName1=" + HttpUtility.UrlEncode("ParamValue1", Encoding.GetEncoding(1251)));

req.ContentLength = SomeBytes.Length;

newStream = req.GetRequestStream();

newStream.Write(SomeBytes, 0, SomeBytes.Length);

newStream.Close();

// считываемрезультатработы

result = req.GetResponse();

ReceiveStream = result.GetResponseStream();

Encoding encode = Encoding.GetEncoding(1251);

sr = new StreamReader( ReceiveStream, encode );

Char[] read = new Char[256];

int count = sr.Read( read, 0, 256 );

string strOut = "";

while (count > 0)

{

String str = new String(read, 0, count);

strOut += str;

count = sr.Read(read, 0, 256);

}

Console.WriteLine("Результат работы запрошенного методом POST скрипта: " + strOut);

}

catch (Exception ex)

{

Console.WriteLine("Ошибка: "+ex.Message);

}

finally

{

if (newStream != null)

newStream.Close();

К-во Просмотров: 122
Бесплатно скачать Статья: Отправка запроса методом POST на сервер из .NET приложения