java求大神帮助java.io.IOException: Invalid Http response

五色程序员 五色程序员 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
各位大神,我在做获取视频流的保存为文件的操作遇到了一个问题
我在]JDK1.6的情况下运行如下代码没有任何问题,但是在JDK1.7的环境下报java.io.IOException: Invalid Http response异常


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();
}

}

...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
五色程序员
Java 51,407 成员 86,137 内容