7 15 Votes

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

Tip by Progger99 | 02/05/2013 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) {

    super.onCreate(savedInstanceState);

    WebView wv = new WebView(this);
    setContentView(wv);

    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.

ReplyPositiveNegative

About the Author

Avatar AuthorThe author has not added a short description to his profile yet.
Show Profile | Message

 

Related Topics

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.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.