【发布时间】:2015-10-08 09:02:49
【问题描述】:
我正在尝试使用来自 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>
【问题讨论】: