Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Problem with getHeaderField()

 
Saloon Keeper
Posts: 10879
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic