繁体   English   中英

通过HTTP请求获取IP摄像机的图片

[英]Get IP camera's picture with HTTP request

我试图通过Java程序的HTTP GET请求访问Foscam C1 IP摄像机的图片。

    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet("http://192.168.1.6:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=USERNAME&pwd=PASSWORD");
    HttpResponse response = httpClient.execute(httpGet);

    InputStream is = response.getEntity().getContent();
    BufferedReader in = new BufferedReader(new InputStreamReader(is));
    String line = null;
    while((line = in.readLine()) != null) {
      System.out.println(line);
    }

该网址在浏览器中可以完美运行。

它写道:

<html><body><img src="../snapPic/Snap_20151008-094559.jpg"/></body></html>

如何获得照片本身?

/////编辑://///

    while((line = in.readLine()) != null) {
      line = line.substring(24, 57); //here I get the needed part
      System.out.println(line);
    }
    //This all stuff should go into the loop:
    HttpGet httpGetPicture = new HttpGet("http://192.168.1.6:88/" + line);
    response = httpClient.execute(httpGetPicture);

    is = response.getEntity().getContent();
    in = new BufferedReader(new InputStreamReader(is));
    line = null;
    while((line = in.readLine()) != null) {
      System.out.println(line);
    }

因此,我还请求获取img网址:答案:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>404 - Not Found</title>
 </head>
 <body>
  <h1>404 - Not Found</h1>
 </body>
</html>

好吧,我将解析图片的URL的img标签,并对此进行请求。

您需要为图像数据使用其他URL参数,请参见http://www.foscam.es/descarga/ipcam_cgi_sdk.pdf

还要查看此C#文章http://blogs.infosupport.com/writing-an-ip-camera-viewer-in-c-5-0/ ,如果您想获得连续的JPEG帧作为MJPEG流,则可以进行调整。 您可以轻松地使该代码适应Java

暂无
暂无

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

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