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
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"));
}
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());
Try replacing "utf-8"
(in the 2nd param) with "BASE64"
.