How to post data for WebView android
Try like below...
Java:
WebView webview = new WebView(this);
setContentView(webview);
String url = "http://www.example.com";
String postData = "username=" + URLEncoder.encode(my_username, "UTF-8") + "&password=" + URLEncoder.encode(my_password, "UTF-8");
webview.postUrl(url,postData.getBytes());
Kotlin:
val webview = WebView(this)
setContentView(webview)
val url = "http://www.example.com"
val postData = "username=${URLEncoder.encode(my_username, "UTF-8")}" +
"&password=${URLEncoder.encode(my_password, "UTF-8")}"
webview.postUrl(url, postData.toByteArray())
Android Webview POST request
In Android you do not use webView
to access the content of the HTTP response. You'll need to use HttpClient for that purpose!
See this nice tutorial which explains the fundamentals! Also see this video if you find it hard!
Hope it helps!
Post data to webview in android
Try this
String url = "http://www.example.com";
String postData = "username=my_username&password=my_password";
webview.postUrl(url,EncodingUtils.getBytes(postData, "BASE64"));
Android Webview POST
Try this:
private static final String URL_STRING = "http://www.yoursite.com/postreceiver";
public void postData() throws IOException, ClientProtocolException {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("foo", "12345"));
nameValuePairs.add(new BasicNameValuePair("bar", "23456"));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL_STRING);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
}
I would recommend doing this as part of an AsyncTask and updating the WebView afterwards
How to send POST data with code in an android webview
Try replacing "utf-8"
(in the 2nd param) with "BASE64"
.
Related Topics
Android Phone Orientation Overview Including Compass
How to Extract Code of .Apk File Which Is Not Working
Are Parameters in Strings.Xml Possible
Tab Not Taking Full Width on Tablet Device [Using Android.Support.Design.Widget.Tablayout]
How to Record Screen and Take Screenshots, Using Android API
First Letter Capitalization for Edittext
How to Create Context Menu for Recyclerview
How to Change Line Color in Edittext
Navigation Drawer to Switch Activities Instead of Fragments
Certpathvalidatorexception:Trust Anchor for Certificate Path Not Found - Retrofit Android
Android -- How to Position View Off-Screen
Restrict Edittext to Single Line
Gridlayout and Row/Column Span Woe