title: android how to send int and double as namevaluepair as http post
body: <p>I've an app where i am trying to send data to a webservice using a http post. The user data is a mixture of strings int and doubles. In the app all are represented as Strings as when i use AsyncTask to run the network call, (so that it's not on the main thread), the params array is of type String.</p>
  
  <p>The problem i have is that the server expects an int sometimes. eg compID is an int that the server expects. When using the http post, i use NameValuePair. This will only accept strings. How can i pass an int or a double to the http post?</p>
  
  <p>In my activity.</p>
  
  <pre><code>String[] params = new String[]{tagCompany, tagId, tagPerson, OUT,
                                  null, null,null, null, null, null}; 
                          AsyncPostData apd = new AsyncPostData();
                          apd.execute(params);
  
  
  
  
  
  private class AsyncPostData extends AsyncTask&lt;String, Void, Void&gt; {
  
          ProgressDialog progressDialog;
  
          @Override
          protected void onPreExecute()
          {
              progressDialog= ProgressDialog.show(NfcscannerActivity.this, 
                      "Connecting to Server"," Posting data...", true);            
          };  
  
  
          @Override
          protected Void doInBackground(String... params) {
  
              nfcscannerapplication.loginWebservice.postData(params[0], params[1], params[2], params[3], params[4],
                      params[5], params[6], params[7], params[8], params[9]);
              return null;
          }
  
           @Override
              protected void onPostExecute(Void result)
              {
               super.onPostExecute(result);
                  if(progressDialog != null)
                  progressDialog.dismiss();
  
              }
      }//end of AsyncPostData 
  </code></pre>
  
  <p>.</p>
  
  <p>My post method</p>
  
  <pre><code>public void postData( String compID, String tagID, String clientID, String carerID, 
              String phoneScanned, String phoneSent, String TXType, String phoneType, String latitude, String longitude) {
          // Create a new HttpClient and Post Header
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://cfweb.yourofficeanywhere.co.uk:88/roadrunner.asmx/PostTransaction");
  
  
          try {
              // Add your data
              List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
              nameValuePairs.add(new BasicNameValuePair("CompanyID", compID));
              nameValuePairs.add(new BasicNameValuePair("TagID", tagID));
              nameValuePairs.add(new BasicNameValuePair("ClientID", clientID));
              nameValuePairs.add(new BasicNameValuePair("CarerID", carerID));
              nameValuePairs.add(new BasicNameValuePair("PhoneScanned", "2010-10-16 16:30 000"));
              nameValuePairs.add(new BasicNameValuePair("PhoneSent", "2010-10-16 16:32 000"));
              nameValuePairs.add(new BasicNameValuePair("TXType", "2"));
              nameValuePairs.add(new BasicNameValuePair("PhoneType", "2"));
              nameValuePairs.add(new BasicNameValuePair("Latitude", latitude));
              nameValuePairs.add(new BasicNameValuePair("Longitude", longitude));
  
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
              // Execute HTTP Post Request
              HttpResponse response = httpclient.execute(httppost);
  
              Log.e(TAG, "response of post = " + response.toString());
  
  
  
          } catch (ClientProtocolException e) {
              // TODO Auto-generated catch block
          } catch (IOException e) {
              // TODO Auto-generated catch block
          }
      } 
  </code></pre>
  
  <p>In my post method some of the values are set to null for now. What i would like to know is how to make compID an int in the NameValuePair. compID comes over from the activity as a String but the server expects an int.</p>