【问题标题】:How to handle continous GET requests?如何处理连续的 GET 请求?
【发布时间】:2019-06-14 14:34:58
【问题描述】:

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

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(); 
    }

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

【问题讨论】:

    标签: c# get aforge ip-camera


    【解决方案1】:

    使用 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
    }
    

    【讨论】:

      【解决方案2】:

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

      这个帖子有几年的历史了,但对于其他感兴趣的人,请使用 step=1 逐步移动。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-25
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        相关资源
        最近更新 更多