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?

Was it helpful?

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top