title: Can't do a HTTP Post to a Web Service from my Android App
body: <p>I've been working on an app that uses both GET and POST requests to Web Services.  The GET requests are no problems but the POST requests are killing me.  I've tried 2 different scenarios in the code.  The first looks like this...</p>
  
  <pre><code> HttpClient httpclient = new DefaultHttpClient();  
   HttpPost httppost = new HttpPost(ws);  
   JSONObject jsonObject = new JSONObject();
  
   try {  
  // Add your data  
  List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);  
  jsonObject.put("action", "login");
  jsonObject.put("username", "*********");
      jsonObject.put("password", "*********");
  
      httppost.setHeader("jsonString", jsonObject.toString());  
  StringEntity se = new StringEntity( jsonObject.toString());    
  se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));  
  httppost.setEntity(se); 
  
  
              // Execute HTTP Post Request  
              HttpResponse response = httpclient.execute(httppost);  
              textview.setText(getResponse(response.getEntity()));
          } catch (ClientProtocolException e) {  
              textview.setText(e.getLocalizedMessage());
          } catch (IOException e) {  
              textview.setText(e.getLocalizedMessage());
          } catch (JSONException e) {
              textview.setText(e.getLocalizedMessage());
          }
  </code></pre>
  
  <p>This code gets this result for me...<br>
  <strong>"Bad Request (Invalid Header Name)"</strong></p>
  
  <p>Now here's my second piece of code...</p>
  
  <pre><code> HttpClient httpclient = new DefaultHttpClient();  
        HttpPost httppost = new HttpPost(ws);  
        JSONObject jsonObject = new JSONObject();
  
          try {  
              // Add your data  
              List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);  
              jsonObject.put("action", "login");
              jsonObject.put("username", "******");
              jsonObject.put("password", "******");
  
              nameValuePairs.add(new BasicNameValuePair("jsonString", jsonObject.toString()));
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
  
              // Execute HTTP Post Request  
              HttpResponse response = httpclient.execute(httppost);  
  
              textview.setText(getResponse(response.getEntity()));
          } catch (ClientProtocolException e) {  
              textview.setText(e.getLocalizedMessage());
          } catch (IOException e) {   
              textview.setText(e.getLocalizedMessage());
          } catch (JSONException e) {
  
          }
  </code></pre>
  
  <p>This gives me an entirely different result.  It's a long garbled mess of xml and SOAP that does have a SOAP Exception mentioned in it...<br>
  <strong>"Server was unable to process request.  --- System.Xml.XmlException: Data at the root level is invalid.  Line 1, position 1."</strong><br>
  Now, can anyone shed any light on what I am doing wrong.</p>