Всем привет! Постала проблема: нужно открыть браузер по умолчанию, любой адресс и передать ему POST параметры. Сделал две разных части: первая ищет браузер по умолчанию (до черты со свездочками) и открывает любой адресс в нем. Вторая, по идее шлет ПОСТ параметры. Но вот по поводу второй я очень сомневаюсь. Может у кого нибудь есть какие то идеи или исходники)) поетому поводу. Как сделать чтобы действие было одновременным: открывался ЮРЛ и слались туда пост параметры? Ткните носом. Спасибо!
Вот мой обработчик кнопки:
private void button1_Click(object sender, EventArgs e)
{
string browser = string.Empty;
RegistryKey key = null;
try
{
key = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command", false);
//trim off quotes
browser = key.GetValue(null).ToString().ToLower().Replace("\"", "");
if (!browser.EndsWith("exe"))
{
//get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe")+4);
}
}
finally
{
if (key != null) key.Close();
}
//open default system browser
System.Diagnostics.Process.Start(browser, strURL.Text);
//***************************************************
//Отсылаю ПОСТ данные
// Convert string data into byte array
string strData = "Name=Sergiy&Age=21";
byte[] dataByte = Encoding.UTF8.GetBytes(strData);
HttpWebRequest POSTRequest = (HttpWebRequest)WebRequest.Create(strURL.Text);
POSTRequest.Method = "POST";
// Set the content type - Mine was xml.
POSTRequest.ContentType = "application/x-www-form-urlencoded";
POSTRequest.KeepAlive = false;
POSTRequest.Timeout = 5000;
POSTRequest.ContentLength = dataByte.Length;
// Get the request stream
Stream POSTstream = POSTRequest.GetRequestStream();
// Write the data bytes in the request stream
POSTstream.Write(dataByte, 0, dataByte.Length);
//Get response from server
HttpWebResponse POSTResponse = (HttpWebResponse)POSTRequest.GetResponse();
}