繁体   English   中英

如何处理连续的 GET 请求?

[英]How to handle continous GET requests?

我正在开发一个小的 Windows 窗体应用程序,它向我展示了我的网络中几个 IP 摄像机(来自不同公司)的流,还允许我移动摄像机(向左、向右、向上、向下、缩放)。 这是通过 AFORGE.net MJPEG Streams 和通过触发获取请求的相机移动来实现的。 问题:我有一台相机,它不会逐步移动(例如,每次点击“向上”后),但它会连续移动。 它仅在我发送带有参数“停止”的另一个请求时停止。

GET 请求向右移动:

http://192.XXX.XX.XXX:XXXX/web/cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=right&-speed=63

GET 请求停止运动:

http://192.XXX.XX.XXX:XXXX/web/cgi-bin/hi3510/ptzctrl.cgi?-step=0&-                                                               act=stop&-speed=63

我用于其他相机的功能:

private void move_right()
    {
    string url = 'someURL';
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "GET";
    request.GetResponse();
    request.Abort(); 
    }

我希望相机在单击按钮后逐步向右移动,但是当发出向右移动的请求时,我的程序就卡住了。

使用 HttpClient 对象并创建一个异步请求,尝试类似(未经测试):

private async Task move_right()
{
    var url = 'someURL';
    var client = new HttpClient();
    var request = new HttpRequestMessage() 
    {
        RequestUri = new Uri(url),
        Method = HttpMethod.Get,
    };

    var response = await client.SendAsync(request);

    //Do something with your response
}

private async Task executeWebRequests() 
{
    //Usage - Await for result
    await move_right();

    //Execute asynchronously
    move_right(); //Will create a new task and run asynchronously in the BG
    move_right(); //Will create a new task and run asynchronously in the BG
    move_right(); //Will create a new task and run asynchronously in the BG
    move_right(); //Will create a new task and run asynchronously in the BG
}

我有一个使用相同网址的相机。

该线程已有几年历史,但对于其他感兴趣的人,请使用 step=1 逐步移动。

云台控制

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM