Java – How to send an HTTP header in java

httphttp-headersjavaurlconnection

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?

Best Answer

Yes, the method you want is setRequestProperty.