715 Votes

Android Programming: Send data via POST to WebView (e.g. to implement an automatic login)

Tip by Progger99 | 2013-05-02 at 11:07

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.


About the Author

AvatarThe author has not added a profile short description yet.
Show Profile


Related Topics

Android Getting Sound Levels

Open Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.