title: How to pass parameter value using HttpPost and NameValuePair in android when accessing rest web service?
body: <p>I made a rest web service with the service contract as shown below</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method = "POST",
              ResponseFormat = WebMessageFormat.Xml,
              BodyStyle = WebMessageBodyStyle.Wrapped,
              UriTemplate = "postdataa?id={id}"
              )]
  string PostData(string id);
  </code></pre>
  
  <p>Implementation of the method PostData</p>
  
  <pre><code>public string PostData(string id)
          {
              return "You posted " + id;
          }
  </code></pre>
  
  <p>Code in Android to post data in web service</p>
  
  <pre><code>HttpClient httpclient = new DefaultHttpClient();
          HttpHost target = new HttpHost("192.168.1.4",4567);
          HttpPost httppost = new HttpPost("/RestService.svc/postdataa?");
  
          String result=null;
          HttpEntity entity = null;
  
          try {
              // Add your data
              List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(1);
              nameValuePairs.add(new BasicNameValuePair("id", "1"));
              UrlEncodedFormEntity ent = new UrlEncodedFormEntity(nameValuePairs);
              httppost.setEntity(ent);
  
              // Execute HTTP Post Request
              HttpResponse response = httpclient.execute(target, httppost);
              entity = response.getEntity();
              //get xml result in string
              result = EntityUtils.toString(entity);
  
  } catch (ClientProtocolException e) {
              // TODO Auto-generated catch block
          } catch (IOException e) {
              // TODO Auto-generated catch block
          }
  </code></pre>
  
  <p><strong>The problem is that the xml result shows and the value of the parameter is missing</strong>:</p>
  
  <pre><code>&lt;PostDataResponse xmlns="http://tempuri.org/"&gt;&lt;PostDataResult&gt;You posted &lt;/PostDataResult&gt;&lt;/PostDataResponse&gt;
  </code></pre>
  
  <p>I do not know what went wrong. </p>