简体   繁体   English

Android应用程序:登录网站,维护会话-Java

[英]Android App: Log-in to website, maintain session - Java

I am new to Android programming and am expecting to developing an app. 我是Android编程的新手,并希望开发一个应用程序。 The app should be able to log-in to a website by filling a HTML form. 该应用程序应该能够通过填写HTML表单登录到网站。

Once logged in the session should be maintained and through out the session, the user must be able to post (using standard HTML form posts) to the website. 登录会话后应予以维护,并在整个会话期间,用户必须能够(使用标准HTML表单发布)发布到网站。

Is this type of activity possible? 这种活动可能吗? Any special modules that I can use for this? 我可以为此使用任何特殊模块吗?

Note: The web-site doesn't have any fancy API. 注意:该网站没有任何精美的API。 Neither do I have access to its source code. 我也无法访问其源代码。

Thank you in advance. 先感谢您。

I wasn't sure of what I was asking at first, after few Bings I landed on what I needed. 一开始我不确定我要问的是什么,在几次Bings之后我就找到了我需要的东西。

The need was to log-in to a web-site by processing a HTML Post form, keep the session and work on the website. 需要通过处理HTML Post表单登录到网站,保持会话状态并在网站上工作。

A simple function to connect to a site is as follows. 连接到站点的简单功能如下。

public static void connectToSite(HttpClient client, String username, String password){
    List<NameValuePair> arguments = new ArrayList<NameValuePair>();
    arguments.add(new BasicNameValuePair("email", username));
    arguments.add(new BasicNameValuePair("pword", password));
    arguments.add(new BasicNameValuePair("action", "modifyPALS"));
    arguments.add(new BasicNameValuePair("Submit", "Login"));

    HttpPost post = new HttpPost();

    try{
        post.setURI(new URI("http://www.my-target-website.com/login.php"));
        post.setEntity(new UrlEncodedFormEntity(arguments));
        client.execute(post);
        AppStatus s = getSiteConnectionStatus(client, site);
    }
    catch (URISyntaxException e){
        Log.e("LANKAFRIENDS", "SiteConnection.connectToSite():URISyntaxException");
    } 
    catch (ClientProtocolException e) {
        e.printStackTrace();
    } 
    catch (IOException e) {
        e.printStackTrace();
    }

}

I get a single instance of an HttpClient through an Singleton implementation. 我通过Singleton实现获得HttpClient的单个实例。 And use it when ever I want. 并在需要时使用它。

Form attributes are stored as BasicNameVluePair s in a List. 表单属性以BasicNameVluePair的形式存储在List中。 An HttpPost object is created, url provided through setURI method. 创建一个HttpPost对象,通过setURI方法提供url。 Then the list is provided to the HttpPost object as an entity and finally executed. 然后,该列表作为一个实体提供给HttpPost对象,并最终执行。

Some thing pretty obvious, lot of instructions in StackOverflow and Bing if you need to find. 有些事情很明显,如果需要查找,可以在StackOverflow和Bing中找到很多说明。

I guess thats it :) 我想就是这样:)

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

相关问题 Java:桌面应用程序可以在Web应用程序中登录并检索“会话”对象以验证其在信任该Web应用程序的其他应用程序中的身份吗? - Java: Can a desktop App log-in in a web app and retrieve a “session” object to authenticate itseft in other apps which trust the web app? 如何维护整个应用程序中的会话,直到用户在android中注销? - how to maintain session in whole app till the user log-out in android? 维护php和Java应用之间的会话/连接 - maintain session/connection between php and java app 存储会话cookie以维护登录会话 - Storing session cookie to maintain log in session Android应用程序,如何登录网站并显示信息? - Android app, how to log into website and display information? 如何通过登录创建简单的Web应用程序? - How do I make a simple web app with log-in? Android Java 在应用程序中显示网站 - Android Java Display website in app 如何在我的登录应用程序中调用SOAP服务? 安卓 - How to call SOAP service in my log-In Application? android Java httpclient登录网站和下载文件 - 会话问题! - Java httpclient to log into website and download file - Session Problems! 登录Java后为所有其他文件存储值 - store value after log-in java for all other files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM