51,410
社区成员
发帖
与我相关
我的任务
分享
package t1;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import sun.net.www.protocol.http.HttpURLConnection;
public class T5 {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
//网络视频流地址
String urlPath = "http://192.168.0.103:81/livestream.cgi?user=admin&pwd=888888&streamid=0&filename=111";
// urlPath ="http://192.168.0.103:81/livestream.cgi";
URL url = new URL(urlPath);
//打开连接开始获取视频流
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.setRequestProperty("Pragma:", "no-cache");
connection.setRequestProperty("Cache-Control", "no-cache");
connection.setRequestProperty("Content-Type", "text/xml");
connection.setRequestProperty("ContentType","text/xml;charset=utf-8");
connection.setRequestProperty("charset", "UTF-8");
connection.setRequestProperty("Accept-Language", "en-us,en;q=0.5");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
File file = new File("C:\\Users\\Administrator\\Desktop\\hOMS\\Avi_9001.mp4");
FileOutputStream outputStream = new FileOutputStream(file);
//connection.getInputStream() 这句报错
InputStream inputStream = connection.getInputStream();
byte[] buff = new byte[1024];
int rc = 0;
while ((rc = inputStream.read(buff, 0, 1024)) > 0) {
outputStream.write(buff, 0, rc);
}
inputStream.close();
outputStream.close();
}
}