GET http://info.kib.ac.cn/down.asp?id=3964&no=1 HTTP/1.0
HOST: info.kib.ac.cnHTTP/1.1 302 Object moved
Server: Microsoft-IIS/5.0
Date: Mon, 14 Mar 2005 04:19:37 GMT
Location: http://info.kib.ac.cn/softwares/Adobe%20Reader%2070_chs_full.exe
Connection: Keep-Alive
Content-Length: 121
Content-Type: text/html
Set-Cookie: ASPSESSIONIDQCTDQBTB=KMKEAGDDMFKMHOBKFNJIIPGI; path=/
Cache-control: private所以读取Location属性就可以了
HOST: info.kib.ac.cnHTTP/1.1 302 Object moved
Server: Microsoft-IIS/5.0
Date: Mon, 14 Mar 2005 04:19:37 GMT
Location: http://info.kib.ac.cn/softwares/Adobe%20Reader%2070_chs_full.exe
Connection: Keep-Alive
Content-Length: 121
Content-Type: text/html
Set-Cookie: ASPSESSIONIDQCTDQBTB=KMKEAGDDMFKMHOBKFNJIIPGI; path=/
Cache-control: private所以读取Location属性就可以了
然后读取location
public void logResponseHead( HttpURLConnection con ) {
for( int i = 1; ; i++ ) {
String header = con.getHeaderFieldKey( i );
if( header != null ) {
NetUtil.log( header + " : " + con.getHeaderField( header ) );
} else {
break;
}
}
}结果:
Server : Microsoft-IIS/5.0Date : Mon, 14 Mar 2005 06:16:16 GMTContent-Type : application/octet-streamLast-Modified : Tue, 25 Jan 2005 02:19:00 GMTETag : "082133b842c51:834"Content-Length : 25172913Content-Range : bytes 5518839-30691751/30691752
getHeaderField
getInputStream
getOutputStream
Certain header fields are accessed frequently. The methods: getContentEncoding
getContentLength
getContentType
getDate
getExpiration
getLastModifed
String out = conn.getInputString();
CookieJar cookie = conn.cookie;
String location = conn.getLocation();
Connect有两种构造方法,并可以直接获得系统的cookie(采用jni,目前只支持window)
public final CookieJar cookie; public final URLParser urlParser; public Connect(String url) {
this(url, new CookieJar(url));
} public Connect(String url, CookieJar cookie) {
this.urlParser = new URLParser(url);
this.cookie = cookie;
this.referer = urlParser.protocol + "://" + urlParser.host;
addConnectListener(this);
}
另外,遍历真的没错,直接con.getHeaderField("Location") is null