Hackjaku
Hackjaku

Reputation: 100

How to open a web page from android application passing credentials?

I'm developing an App for my company, basically we need just a launcher to skip opening the browser and typing the address. I have two text boxes in my app and a login button. It's okay to launch the default browser (OpenAsync works just fine, but I can't pass the credentials). We already have a webapp which requires username and password and we have to reach it from anywhere using a VPN. I'd like to save the credential from the app, send them thru it when pressing the login button and load the page already authenticated. Security is not a concern at the moment since we're not managing private data.

I'm new to this world and I'm not sure how HttpRequests and WebRequests work. I just tryed many solutions i found online, but none of them worked for me. Probably I just miss the point there.

WebRequest request = WebRequest.Create("http://www.example.com/login");
request.Method = "POST";
string postData = "username=usr&password=pass1234";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);

Upvotes: 1

Views: 1550

Answers (3)

try this "www.example.com?username=" + username + "&password=" + password;

where as username and password are String variables containing your credential values

Upvotes: 0

Gaurav Mathur
Gaurav Mathur

Reputation: 849

Credentials passed via query string will not auto populate the login page boxes with the values passed.

You have to modify you web app's login page to accept username and passwords passed via query string and authenticate user.

Upvotes: 1

Milan Joseph
Milan Joseph

Reputation: 118

Pass the username and password as url parameter and from webapp access the username and password.

Upvotes: 1

Related Questions