With the following code, it is possible to send data to a WebView using POST with Android:


public void onCreate(Bundle savedInstanceState) {
    WebView wv = new WebView(this);
    String url = "http://www.example.com/login.php";
    String data = "name=Test&password=12345";
    wv.postUrl(url, EncodingUtils.getBytes(data, "base64"));

This code creates a new WebView and opens the website example.com/login.php in it. When opening the page, the data stored in "data" is passed via POST to the web page.

The code can be used, for example, to implement an automatic login by sending the login data via POST to the login page. In th example, we are sending the variables "name" and "password", but, of course, it is also possible to use the code for any other purpose.


全文取自 http://www.askingbox.com/tip/android-programming-send-data-via-post-to-webview-e-g-to-implement-an-automatic-login 



Frank 發表在 痞客邦 PIXNET 留言(0) 人氣()