N***m 发帖数: 4460 | 1 String urlName = "http://127.0.0.1:8080/docs/changelog.html";
URL url = new URL(urlName);
URLConnection connection = url.openConnection();
connection.connect();
Map> headers = connection.
getHeaderFields();
for(Map.Entry> entry: headers.entrySet(
)) {
System.out.print(entry.getKey()+": ");
for(String s:entry.getValue())
System.out.print(s+",");
System.out.println();
}
Scanner in = new Scanner(connection.getInputStream());
for(int i=0;i<10&&in.hasNext();i++) {
String line = in.nextLine();
System.out.println(line);
}
得到
=================================================
null: HTTP/1.1 200 OK,
ETag: W/"78363-1287113226000",
Date: Tue, 04 Jan 2011 18:32:10 GMT,
Content-Length: 78363,
Last-Modified: Fri, 15 Oct 2010 03:27:06 GMT,
Accept-Ranges: bytes,
Content-Type: text/html,
Server: Apache-Coyote/1.1,
==================================================
为啥第一个entry的key是null? |
X****r 发帖数: 3557 | 2 That's the status line of the HTTP response, technically not
a header field. See RFC 2616.
headers.entrySet(
【在 N***m 的大作中提到】 : String urlName = "http://127.0.0.1:8080/docs/changelog.html"; : URL url = new URL(urlName); : URLConnection connection = url.openConnection(); : connection.connect(); : Map> headers = connection. : getHeaderFields(); : for(Map.Entry> entry: headers.entrySet( : )) { : System.out.print(entry.getKey()+": "); : for(String s:entry.getValue())
|
N***m 发帖数: 4460 | 3 抱歉,用错术语了。我只是想知道
为啥第一个key是null阿?
【在 X****r 的大作中提到】 : That's the status line of the HTTP response, technically not : a header field. See RFC 2616. : : headers.entrySet(
|
X****r 发帖数: 3557 | 4 ... did I just say it is not a header? That's why
it doesn't have a key (field name).
【在 N***m 的大作中提到】 : 抱歉,用错术语了。我只是想知道 : 为啥第一个key是null阿?
|
N***m 发帖数: 4460 | 5 ft, 谁设计的这个map,有key无key混杂在一起?
第一个写成protocal之类的不是挺好的嘛?any reason why not doing this?
【在 X****r 的大作中提到】 : ... did I just say it is not a header? That's why : it doesn't have a key (field name).
|
X****r 发帖数: 3557 | 6 Not me ;-)
Sometimes you are stuck with existing interface, and this is one
of those times.
【在 N***m 的大作中提到】 : ft, 谁设计的这个map,有key无key混杂在一起? : 第一个写成protocal之类的不是挺好的嘛?any reason why not doing this?
|
M**u 发帖数: 10158 | 7 第一项是response status line
后面的才是属性
entrySet(
【在 N***m 的大作中提到】 : String urlName = "http://127.0.0.1:8080/docs/changelog.html"; : URL url = new URL(urlName); : URLConnection connection = url.openConnection(); : connection.connect(); : Map> headers = connection. : getHeaderFields(); : for(Map.Entry> entry: headers.entrySet( : )) { : System.out.print(entry.getKey()+": "); : for(String s:entry.getValue())
|
N***m 发帖数: 4460 | 8 为啥搞getHeaderFields的javaer把它放在map里面萨?
一开始我还以为我搞错什么了,浪费了不少时间,太害人了。
【在 M**u 的大作中提到】 : 第一项是response status line : 后面的才是属性 : : entrySet(
|