使用HTTP请求获取IP摄像机的图片

时间:2015-10-08 09:02:49

标签: java http-get ip-camera

我正在尝试使用来自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 url的get请求: 回答:

<?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>

1 个答案:

答案 0 :(得分:1)

您需要为图像数据使用其他网址参数,请参阅 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