首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTTPUrlConnection和.torrent文件

HTTPUrlConnection和.torrent文件
EN

Stack Overflow用户
提问于 2014-12-18 01:17:20
回答 1查看 153关注 0票数 1

我正在尝试创建独立的file服务器,以编程方式搜索torrent文件(例如.从torrentz.eu下载。

我完全疯了下载单个洪流文件,它似乎服务器响应是不同的使用浏览器或java。

这是一个脚本:

代码语言:javascript
复制
      connection = (HttpURLConnection)url.openConnection();

            connection.setRequestProperty("Cookie", cookies);
                    System.setProperty("http.agent", "");
                    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");

                    connection.setRequestMethod("GET");
                    connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                    connection.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
                    connection.setRequestProperty("Connection", "keep-alive");
                    connection.setRequestProperty("Content-Language", "en-US");
                    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    connection.setRequestProperty("Connection", "Keep-Alive");            
                    connection.setConnectTimeout(22000);
                    connection.setReadTimeout(12000);
                    connection.setUseCaches(false);
                    connection.setDoInput(true);
                    connection.setDoOutput(true);

    connection.connect();
    respCode = connection.getResponseCode();

    if(respCode != 200){
    // do something..
    return false;
    }

    ByteArrayOutputStream list = new ByteArrayOutputStream();
stream = connection.getInputStream();

            byte[] buffer = new byte[512];
            int c;
            while ((c = stream.read(buffer)) != -1) {
                if(c > 0){
                    list.write(buffer, 0, c);
                }
            }
            list.flush();
            stream.close();

此代码适用于html、图像文件、ecc。但是不可能获得.torrent文件,它们已经损坏:

例子: UBUNTU,https://torcache.net/torrent/B415C913643E5FF49FE37D304BBB5E6E11AD5101/[katproxy.com]ubuntu.14.10.desktop.64bit.iso.torrent

  • 浏览器下载的.torrent文件大小: 44920字节
  • java下载的.torrent文件大小: 44795字节135字节丢失!只是为什么??
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-18 02:18:30

发现问题了!

文件被压缩了!可能,默认情况下浏览器会自动解压.非常感谢你!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27537703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档