Post data to webview in android

前端 未结 4 1909
别那么骄傲
别那么骄傲 2020-12-10 06:36

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

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

engine.setWebViewClient(new WebViewClient         


        
相关标签:
4条回答
  • 2020-12-10 06:51

    Try this

    String url = "http://www.example.com";
    String postData = "username=my_username&password=my_password";
    webview.postUrl(url,EncodingUtils.getBytes(postData, "BASE64"));
    
    0 讨论(0)
  • 2020-12-10 07:02

    Use postUrl to use POST in WebView.

    0 讨论(0)
  • 2020-12-10 07:03

    Better with Base64.encode:

    String url = "http://www.example.com";
    String postData = "username=my_username&password=my_password";
    webview.postUrl(url,Base64.encode(postData.getBytes(), Base64.DEFAULT));
    

    In some cases works better:

    String url = "http://www.example.com";
    postData = "username="+URLEncoder.encode("my_username", "UTF-8")+"&password="+URLEncoder.encode("my_password", "UTF-8");
     webview.postUrl(url,postData.getBytes());
    
    0 讨论(0)
  • 2020-12-10 07:15

    Use postUrl Method for post dat. More detail Follow This.

    0 讨论(0)
提交回复
热议问题