title: Android Webview POST
body: <p>I am trying to accomplish something quite simple, yet I have found no good documentation on this. I have a webView, and I need to load a page in it that requires POST data. Seems like a simple process, yet I cannot find a way to display the result in a webView.</p>
  
  <p>The process should be simple:</p>
  
  <p>query(with POST data) -> webserver -> HTML response -> WebView.</p>
  
  <p>I can submit data using a DefaultHttpClient, but this cannot be displayed in a WebView.</p>
  
  <p>Any suggestions?</p>
  
  <p>Much Thanks</p>
  
  <p>Solution</p>
  
  <pre><code>private static final String URL_STRING = "http://www.yoursite.com/postreceiver";
  
      public void postData() throws IOException, ClientProtocolException {  
  
           List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();  
           nameValuePairs.add(new BasicNameValuePair("foo", "12345"));  
           nameValuePairs.add(new BasicNameValuePair("bar", "23456"));
  
           HttpClient httpclient = new DefaultHttpClient();  
           HttpPost httppost = new HttpPost(URL_STRING);  
           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
  
           HttpResponse response = httpclient.execute(httppost);  
           String data = new BasicResponseHandler().handleResponse(response);
           mWebView.loadData(data, "text/html", "utf-8");
      }
  </code></pre>