Hi,
I am trying to send params to a Servlet which accepts only PUT requests. When I append the params in the URL the values of those are passed to the Servlet but if I use the BasicNameValuePair to send the params it does not work, I mean the params values in the servlet are null.
Here's the code which works
Code:
HttpClient httpClient = null;
HttpResponse response = null;
HttpPut httpPut = null;
StatusLine statusLine = null;
try {
httpPut = new HttpPut("http://localhost:8080/Test_app/details?customerId=122&productId=pp");
HttpParams httpParams = new BasicHttpParams();
int timeOut = 0;
HttpConnectionParams.setConnectionTimeout(httpParams, timeOut);
httpClient = new DefaultHttpClient(httpParams);
response = httpClient.execute(httpPut);
But I want to set the query params like below Parameters are going to the servlet. but the values are null in the servlet
Code:
HttpClient httpClient = null;
HttpResponse response = null;
HttpPut httpPut = null;
StatusLine statusLine = null;
try {
httpPut = new HttpPut("http://localhost:8080/Test_app/details");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("customerId", URLEncoder.encode("123456","UTF-8")));
nameValuePairs.add(new BasicNameValuePair("productId", URLEncoder.encode("pp12","UTF-8")));
httpPut.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpParams httpParams = new BasicHttpParams();
int timeOut = 0;
HttpConnectionParams.setConnectionTimeout(httpParams, timeOut);
httpClient = new DefaultHttpClient(httpParams);
response = httpClient.execute(httpPut);
Also how do I send an xml in request body for the same HttpPUT request.
Thanks for the help!!