Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with getHeaderField()

 
Carey Brown
Bartender
Posts: 1940
24
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic