| 发表于:2008-02-18 11:22:51 楼主 |
有没有人做过这样一件事情: http连接的时候可以设置自动跳转或者不自动跳转,如果我们设置为不自动跳转,那么我们将收到302的responcode.并且在location里面我们将可以获得将要跳转到的url。到这里一切都没有问题。 但是,我经常发现,我想通过某个url跳转之后,下载对应的:application/***,(并且设置为不允许跳转),获得的location里面并没有application/***的真正url。不仅如此,在整个返回的httphead里面都找不到任何一个url 能于application/***对应起来,到这估计大家都会说,这说明这个url根本无法获得application/***,确实,我也觉得很有道理,我用ie试过,确实无法将application下载下来。但是用flash-get或者迅雷试一下,却发现可以下载正确的application. 请教一下,flash-get 迅雷,他们到底做了什么事情呢? example: url = http://86516.onlinedown.net/down/winzip111zh.zip 用ie打开,直接跳转到华军软件的首页, 用firefox打开,可以将application下载下来 自己代码尝试: java.net.url url = new java.net.url(strurl); httpurlconnection httpconnection = (httpurlconnection)url.openconnection(); if (httpconnection != null) { httpurlconnection.setfollowredirects(false); httpconnection.setrequestproperty("user-agent","bronco"); responsecode = httpconnection.getresponsecode(); int i = 1; while (true) { string key = httpconnection.getheaderfieldkey(i++); if (key == null) { break; } string value = httpconnection.getheaderfield(key); system.out.println(key + " : " + value); //省略200字 respon code is 200 输出信息如下: etag : "ae67b82eac64c81:f21" date : mon, 18 feb 2008 03:19:50 gmt content-length : 27139 last-modified : fri, 01 feb 2008 08:26:46 gmt content-location : http://www.newhua.com/hj_index.htm accept-ranges : bytes content-type : text/html x-powered-by : asp.net server : microsoft-iis/6.0 我就想不通了,从这个header里面怎么可能获得application/所对应的url呢? |
|
|
|
|