我尝试在点击按钮时发布到URL(以启用相机的触发脉冲)。我有一个类似的代码来点击按钮禁用触发脉冲。我面临的问题是,行动完成的延迟异常高。我无法弄清楚为什么它有时会提前完成并且有时需要很长时间。有人可以帮忙吗?
private void button2_Click_1(object sender, EventArgs e)
{
try
{
string requestmethod = "POST";
string postData = "";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
string URL = "http://192.168.0.42/entrig.cgi";
string contenttype = "application/x-www-form-urlencoded";
request = null;
request = (HttpWebRequest)WebRequest.Create(URL);
Stream dataStream;
((HttpWebRequest)request).KeepAlive = false;
request.Method = requestmethod;
request.ContentType = contenttype;
request.ContentLength = byteArray.Length;
dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
MessageBox.Show("Started Trigger");
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace);
}
}