Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post data to webview in android

Tags:

android

Does anyone know how to pass value in webview using post method?

engine = (WebView) findViewById(R.id.web_engine);

engine.setWebViewClient(new WebViewClient() {

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return super.shouldOverrideUrlLoading(view, url);
    }
});

engine.getSettings().setJavaScriptEnabled(true);
engine.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
engine.loadUrl(url+"?ref=api&uname="+id+"&pass="+pass);

This is the way I am sending the data using get method, I want to use Post method.

like image 623
ajaylouis Avatar asked Nov 02 '12 07:11

ajaylouis


2 Answers

Try this

String url = "http://www.example.com";
String postData = "username=my_username&password=my_password";
webview.postUrl(url,EncodingUtils.getBytes(postData, "BASE64"));
like image 122
TNR Avatar answered Sep 28 '22 13:09

TNR


Use postUrl to use POST in WebView.

like image 44
Rajesh Avatar answered Sep 28 '22 12:09

Rajesh