对URL的POST请求消息需要异常时间

时间:2009-04-20 07:07:02

标签: c# .net httpwebrequest

我尝试在点击按钮时发布到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);
    }
}

1 个答案:

答案 0 :(得分:0)

没有理由认为服务器是一致的。尝试监控什么是无线(例如Fiddler)并查看减速的位置。