CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2014
    Posts
    1

    Exclamation Need Urgent Help with HttpPut request parameters

    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!!

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Need Urgent Help with HttpPut request parameters

    What packages are those classes in? I don't see them in the java SE API doc.
    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured