How to send POST data with code in an android webview

后端 未结 3 1235
刺人心
刺人心 2020-12-13 13:26

I have an android application that consists of a WebWiew and I need to login to a site automatically using code. I\'ve tried using postUrl() and it

相关标签:
3条回答
  • 2020-12-13 14:13
    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
    
        WebView webView = new WebView(this);
    
        setContentView(webView);
    
        String url = "http://example.com/somepage.php";
        String postData = "postvar=value&postvar2=value2";
    
        webView.postUrl(url, EncodingUtils.getBytes(postData, "base64"));
    }
    
    0 讨论(0)
  • 2020-12-13 14:14
    WebView myWebView = (WebView) findViewById(R.id.webview);
    
    String url="http://www.example.org/login";
    
    String postData=
                    "username="+URLEncoder.encode("abc","UTF8")+
                    "&password="+URLEncoder.encode("***", "UTF-8");
    
    myWebView.postUrl(url,postData.getBytes());
    
    0 讨论(0)
  • 2020-12-13 14:20

    Try replacing "utf-8" (in the 2nd param) with "BASE64".

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