my dog learned polymorphism*
The moose likes Sockets and Internet Protocols and the fly likes Problem with getHeaderField() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Problem with getHeaderField()" Watch "Problem with getHeaderField()" New topic
Author

Problem with getHeaderField()

Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 170

The following code seems to work correctly because I can retrieve the contents of the URL ok, but I don't get any results from the getHeaderField() call. Any ideas?

URL url = new URL( urlstr );
HttpURLConnection con = (HttpURLConnection)
url.openConnection();
con.setRequestMethod( "GET" );
con.setDoInput( true );
con.setDoOutput( false );
con.connect();
// display header fields
for( int i=0 ; ; i++ )
{
String key;
if( (key = con.getHeaderFieldKey(i)) ==
null )
break;
System.out.println( key + " = "
+ con.getHeaderField(i) );
}
// etc.
srinivas madugula
Greenhorn

Joined: Apr 12, 2003
Posts: 6
hai
the indexing begins at 1 not 0.
getHeaderFieldKey(0) returns null
getHeaderField(0) returns the http response
HTTP/1.0 status some_info_regarding status.
getHeaderFieldKey(1..) returns header key
getHeaderField(1..) returns header value
your program stops on i=0.
start with i=1;
it will work
bye
kumar
 
 
subject: Problem with getHeaderField()
 
Similar Threads
Content of HTTPUrlConnection
How to recive / return cookies to server?
How to get http header infomation in HttpURLConnection
How do I find URL after redirection?
Problem HTTPSURLConnection for Siteminder authentictaion