Все игры
Запись

Не могу обуздать код. Помогиииитее! =)


Нравится

Вы не можете комментировать, т.к. не авторизованы.


Alex V.      25-08-2009 09:28 (ссылка)
Re: Не могу обуздать код. Помогиииитее! =)
не очень красиво, но работает:
//принятия ответа

byte [] reqData = new byte [500];

while (Request.InputStream.BeginRead(reqData, 0, reqData.Length, null, null) != null)
{
Request.InputStream.Read(reqData,0,reqData.Length);
string strReq = UTF8Encoding.UTF8.GetString(reqData);

if (strReq.IndexOf("\0") != 0)
{
//отделяем мух от котлет
}
}

//посылка запроса

Uri address = new Uri("куда");

HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";

byte[] byteData = UTF8Encoding.UTF8.GetBytes("текст который посылаем");

request.ContentLength = byteData.Length;

using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);// сам запрос
}

// здесь принимаем ответ от того кому послали запрос
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string respose = reader.ReadToEnd();// здесь ответ
}