通过 HTTP 请求获取网络摄像机的图片
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);
}
url 在浏览器中完美运行。
它写了这个:
<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 进行了获取请求:
答案:
<?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
我正在尝试使用来自 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);
}
url 在浏览器中完美运行。
它写了这个:
<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 进行了获取请求: 答案:
<?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