Android WebView Login on Android

I have an application that displays asp pages using WebView, but some of the pages want authentication (Username, Password) to log in. I want my application to automatically go to this page using Username and Password from my application.

This is my code:


public class eadvantage extends Activity { /** Called when the activity is first created. */ WebView mWebView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.eadvantage); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.ucsi.edu.my/advantage/new/main.asp"); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("txtUserID", "12345)); nameValuePairs.add(new BasicNameValuePair("txtPassword", "12345")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl("http://www.ucsi.edu.my/advantage/new/main.asp"); mWebView.setWebViewClient(new WebViewClient()); 
+4
source share
1 answer

I'm new ... here's the solution .. but it doesn't sound good at all

1) Create an action to log in. This can be initiated from the menu options in your application or by default, so that whenever your application is launched, the first login screen is displayed.

2) Obtain credentials and authenticate them .. if they are passed, than store them in cookies. I assume Android apps can write cookies

3) Next, on the ASP.net website, check if there are any cookies .. if so .. get the username and pwd values ​​and make them automatically log in (this should be easy .. as we do this often, when the user chooses to remember me option in the login form)

So now that ur webview is running .. users will automatically register

0
source

Source: https://habr.com/ru/post/1336245/


All Articles