I tried to found a solution for this, even found numerous solutions but none resolved my issue.
I am trying to implement a Java client which will consume a Restful web service
.
I want to set parameters inside header which I can retrieve on my web server. My code is;
URL url = new URL("http://servierIP/address");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("firstParam", "hi");
conn.addRequestProperty("secondParam","12345" );
conn.setRequestProperty("Content-Type", "application/xml");
conn.connect();
However, when I try to get values from header, I get NULL
.
I tried to do it with addRequestProperty
and setRequestProperty
both, but still the values are not getting set inside my header.
and the output I am getting when I try to fetch header value is:
null : [HTTP/1.1 200 OK]
Expires : [Thu, 19 Nov 1981 08:52:00 GMT]
Access-Control-Allow-Orgin : [*]
Set-Cookie : [dsfjskfjdsfjskf ---- some value]
Access-Control-Allow-Methods : [*]
Connection : [Keep-Alive]
Server : [Apache/2.2.15 (CentOS)]
X-Powered-By : [PHP/5.3.3]
Cache-Control : [no-store, no-cache, must-revalidate, post-check=0, pre-check=0, public, public]
Pragma : [no-cache, public, public]
Date : [Tue, 26 Aug 2014 05:33:10 GMT]
Transfer-Encoding : [chunked]
Content-Type : [application/xml; charset=utf-8]
If anyone can resolve the issue, I would be very grateful..
Thank you.