How to set headers when i am using java.net.URL
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   asha_Channad
Posted On:   Thursday, April 3, 2008 05:09 AM

I am using the following code to hit the servlet and get response from the servlet. i want to set request headers before hitting the sevlet. how can i achieve? URL url = new URL(requestURL); HttpClient client = new HttpClient(); int statusCode = 0; int timeout = 30; client.getHttpConnectionManager().getParams().setSoTimeout(timeout * 1000); HostConfiguration hcfg = new HostConfiguration(); hcfg.setHost(url.getHost(), url.getPort()); get = new GetMethod(url.toString()); statusCode = client.executeMethod(hcfg, get); if(statusCode==200) String response = get.getResponseBodyAsString();    More>>

I am using the following code to hit the servlet and get response from the servlet. i want to set request headers before hitting the sevlet. how can i achieve?




URL url = new URL(requestURL);
HttpClient client = new HttpClient();
int statusCode = 0;
int timeout = 30; client.getHttpConnectionManager().getParams().setSoTimeout(timeout * 1000);
HostConfiguration hcfg = new HostConfiguration();
hcfg.setHost(url.getHost(), url.getPort());
get = new GetMethod(url.toString());
statusCode = client.executeMethod(hcfg, get);

if(statusCode==200)
String response = get.getResponseBodyAsString();

   <<Less

Re: How to set headers when i am using java.net.URL

Posted By:   Stephen_McConnell  
Posted On:   Monday, April 7, 2008 04:54 PM

Unfortunately, I don't think there is a Java API that sets the header fields in the same way "getHeaderField()" retrieves it. What I remember having to do was create them in as a String in the proper format and then insert them into the URL stream in front of everything.


Stephen McConnell

About | Sitemap | Contact