You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Ashish Kulkarni <as...@gmail.com> on 2007/10/16 20:46:10 UTC

how to set parameters in doGet method

Hi
Suppose i have an URL http://myhost:8080/myServlet?test=abc&test1=klm

Now i need to set parameters test and test1,
the code i have is

HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://myhost:8080/myServlet");
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new
DefaultHttpMethodRetryHandler(3, false));
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
InputStream is =method.getResponseBodyAsStream();


Now how do i add test and test1 parameters to be passed to the URL

Ashish

RE: how to set parameters in doGet method

Posted by hefeng <he...@gmail.com>.
Similar with posting a form in PostMethod, you can use the NameValuePair[]
to hold the parameters and set the parameters with
HttpMethodBase#setQueryString(NameValuePair[] params).

-----Original Message-----
From: Ashish Kulkarni [mailto:ashish.kulkarni13@gmail.com] 
Sent: Wednesday, October 17, 2007 2:46 AM
To: httpclient-user@jakarta.apache.org
Subject: how to set parameters in doGet method

Hi
Suppose i have an URL http://myhost:8080/myServlet?test=abc&test1=klm

Now i need to set parameters test and test1,
the code i have is

HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://myhost:8080/myServlet");
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new
DefaultHttpMethodRetryHandler(3, false));
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
InputStream is =method.getResponseBodyAsStream();


Now how do i add test and test1 parameters to be passed to the URL

Ashish


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org