简体   繁体   English

登录HTTPS ASPX页面的Android应用

[英]Android App that logs in to HTTPS ASPX page

Just to make things clear, I have virtually no experience in HTTP. 为了清楚起见,我几乎没有HTTP经验。 This project is very ambitious for me, but I am willing to learn in order to be able to accomplish it. 这个项目对我来说非常雄心勃勃,但是我愿意学习以实现它。 I have done some searching for examples across the net, but I can't seem to find an adequate solution. 我已经在网上搜索了一些示例,但是似乎找不到合适的解决方案。 I am aware of terms like GET and POST and understand the basic way to programmatically interact with a website. 我知道诸如GET和POST之类的术语,并且了解与网站进行编程交互的基本方式。

Basically, the company I'm working with has a website with a database of clients that I can login to. 基本上,与我合作的公司都有一个网站,其中包含一个我可以登录的客户数据库。 For starters, I just want to be able to write an Android app that is able to login to the main page with my Username and Password. 首先,我只想编写一个Android应用程序,该应用程序可以使用我的用户名和密码登录到主页。 The site has a login URL of https://"app.companysite.com"/Security/Login.aspx?ReturnUrl=%2fHome%2fDefault.aspx and has a certificate that is for the following purpose: "Ensures the identity of a remote computer". 该网站的登录URL为https://“ app.companysite.com” /Security/Login.aspx?ReturnUrl=%2fHome%2fDefault.aspx,并具有用于以下目的的证书:“确保远程计算机”。

Is what I'm doing possible? 我正在做什么? Eventually I would like to be able to open up a Client page and edit their data and re-submit it, but one step a time. 最终,我希望能够打开“客户端”页面并编辑其数据并重新提交,但一次只能执行一次。

It would be awesome if you could either point me in the direction of some relevant reading material or source code that could help me accomplish my goal. 如果您可以向我介绍一些相关的阅读材料或源代码,这些内容可以帮助我实现自己的目标,那就太好了。

Thanks in advance! 提前致谢!

I don't know if this helps, but the way I did my logins is just for justification. 我不知道这是否有帮助,但是我登录的方式只是为了证明。 So What I did (since I am assuming the verification is done through a MySQL database) is to create a php file that just verifies the login username and passwords are correct and print out a "correct" or "Yes" otherwise just a "No" or "invalid". 所以我所做的(因为我假设验证是通过MySQL数据库完成的)是创建一个php文件,该文件仅验证登录用户名和密码是否正确,并打印出“正确”或“是”,否则打印出“否” ”或“无效”。 Something like this : 像这样的东西:

php
//Connects to your Database

      $username = $_POST['username'];
      $password = $_POST['password'];

      //make your mysql query if the username and password are in the database
      //if there is a an approval
     $approval = 1 
     //otherwise
     $approval = 0

    if ($approval > 0) {
       echo "correct";
    } else {
       echo "invalid";
    }

    ?>

Now in Android you could make this request to call this website and return the output like the following : 现在,在Android中,您可以发出此请求来调用此网站并返回如下输出:

HttpParams httpParameters = new BasicHttpParams();
//make a timeout for the connections in milliseconds so 4000 = 4 seconds                    httpParameters.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
int timeoutConnection = 4000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
int timeoutSocket = 4000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

HttpClient httpclient = new DefaultHttpClient(httpParameters);
HttpPost httppost = new HttpPost("your website URL");

// Add your data
String username = "your username";
String password = "your password";

List<NameValuePair> nameValuePairs;
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);

BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

String lines = "";
String data = null;
ArrayList<String> al = new ArrayList<String>();

while((lines = in.readLine()) != null){
    data = lines.toString();
    al.add(data);
}
in.close();

//To get the response
if(al.get(0).equals("correct")){
      //Your login was successful
}
else {
    //Your login was unsuccessful
}

I hope this helped you a bit and pointed you in the right direction. 希望这对您有所帮助,并为您指明了正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM