由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - url header问题
相关主题
Question about which header file declares ntohs() in c++ ?
[合集] 再弱问java:这是java version不同造成的吗?问一下关于http persistent connection的问题
新手求问一C++初级问题HTTP Error 403
Spring REST+AFNetworking问题Re: How to write this makefile?
请教一个Android的简单HTTP REST编程问题 (转载)[转载] 请问DATAGRID里的BOUNDCOLUMN HEADER可以又有TEXT又有
how to convert GMT to timestamp of the computer's current timeHow to see the content of a library file
菜鸟求助:怎么自动include header file?size of structure
ask a question about compile shared library using libtoolA function can be history-sensitive??????
相关话题的讨论汇总
话题: string话题: url话题: 78363话题: urlname话题: gmt
进入Programming版参与讨论
1 (共1页)
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(

1 (共1页)
进入Programming版参与讨论
相关主题
A function can be history-sensitive??????请教一个Android的简单HTTP REST编程问题 (转载)
Question about friend in C++how to convert GMT to timestamp of the computer's current time
最初级的白痴C++问题菜鸟求助:怎么自动include header file?
一道面试怪题C++. (转载)ask a question about compile shared library using libtool
Question about which header file declares ntohs() in c++ ?
[合集] 再弱问java:这是java version不同造成的吗?问一下关于http persistent connection的问题
新手求问一C++初级问题HTTP Error 403
Spring REST+AFNetworking问题Re: How to write this makefile?
相关话题的讨论汇总
话题: string话题: url话题: 78363话题: urlname话题: gmt