How to send an HTTP header in java

Simonw picture Simonw · May 4, 2009 · Viewed 42k times · Source

Is it possible to send a Http header via a URL connection in java? I had this working using sockets, but ran into issues with a firewall which don't seem to be a problem with URLConnection. From looking at the API I get the impression that the output methods in URLConnection are just for filling in forms etc, or can they be used to send my own HTTP headers?

Answer

Matthew Flaschen picture Matthew Flaschen · May 4, 2009

Yes, the method you want is setRequestProperty.