понедельник, 19 ноября 2012 г.

C# - WebRequest class

using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Collections;
using System.IO;

namespace BlankTimeLine.Framework.Core

{

class ServerRequest

{

HttpWebResponse response = null;
HttpWebRequest req;

Hashtable htResponse;

public ServerRequest()
{
htResponse = new Hashtable();
}

public void SendCommand(Hashtable htHttpRequestParams)
{
req = (HttpWebRequest)HttpWebRequest.Create("http://localhost/" + htHttpRequestParams["script"].ToString());
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";

byte[] sentBytes = null;
string sendParams = "";

foreach(DictionaryEntry entry in htHttpRequestParams)
{
sendParams += entry.Key + "=" + entry.Value + "&";
}

// System.Windows.Forms.MessageBox.Show(sendParams);

sentBytes = Encoding.UTF8.GetBytes(sendParams);
req.ContentLength = sentBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(sentBytes, 0, sentBytes.Length);
newStream.Close();

try
{
response = (HttpWebResponse)req.GetResponse();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "Исключение:");
}
}
public Stream GetResponseStream()
{
return response.GetResponseStream();
}
}
}

Комментариев нет:

Отправить комментарий

Arduino IDE (Esp32s3)

1. Установка Arduino IDE (arduino.cc). Подготовка для программирования Esp32S3. 2. Additional board manager URLs: "https://raw.githubus...