How to send an HTTP header in java
-
03-07-2019 - |
Question
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?
Solution
Yes, the method you want is setRequestProperty.
OTHER TIPS
The method you want is setRequestProperty, but I would recommend to use Apaches HttpClient. With this library you have total control over the request you want to send.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow