How to send an HTTP header in java

42,480

Solution 1

Yes, the method you want is setRequestProperty.

Solution 2

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.

http://hc.apache.org/httpclient-3.x/tutorial.html

Share:
42,480
Simonw
Author by

Simonw

24 y/o Developer from Dublin, Ireland. Interested in Java, Android and Scala

Updated on April 11, 2020

Comments

  • Simonw
    Simonw about 4 years

    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?