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

五色程序员 2017-04-26 10:49:28
各位大神,我在做获取视频流的保存为文件的操作遇到了一个问题
我在]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();
}

}

...全文
707 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,410

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧