Hi, 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?
+7
A:
I would recommend to use Apaches HttpClient. With this library you have total control over the request you want to send.
HaBaLeS
2009-05-04 09:46:35
Yes, httpclient is de-facto standard for accessig HTTP from Java.
stepancheg
2009-05-04 09:51:26
Thanks, thats probably the best way to do it, but I should have mentioned I need to stick to the standard java libraries
Simonw
2009-05-04 12:17:20
HttpClient is all well in good, but it's not always necessary, and he asked about URLConnection. And you didn't even mention the relevant method, which is HttpMessage.setHeader (http://hc.apache.org/httpcomponents-core/httpcore/apidocs/org/apache/http/HttpMessage.html#setHeader(java.lang.String,%20java.lang.String)).
Matthew Flaschen
2009-05-04 13:14:05
Your right I could have mentioned the right Method. But as the Questionnaire was asking playing around with Sockets and UrlConnection its no Problem to point out another alternative which is flexible enough to be prepared for upcoming demands
HaBaLeS
2009-05-04 13:24:32