通过httpclient发送html命令android
我试图通过解析相关数据的网页,然后允许用户发送回数据到服务器,从而将Web界面转变为一个Android界面。使用简单的HttpClient代码,我设法获取网页,然后解析必要的信息。我不熟悉发回数据,所以,我希望有人能够阐明一些看法。以下是来自登录页面的相关HTML代码。通过httpclient发送html命令android
<table cellspacing=0 cellpadding=0><tr><td valign=top align=center>
<table cellspacing=0 cellpadding=0 border=0 width=220 align=center class=table_back><tr><td>
<table cellspacing=1 cellpadding=1 border=0 width=100%>
<tr class=table_row1><form action="i.cfm?&1028&p=login&se=4" method=post name=stepform><Td align=right nowrap> Empire Name </td><td> <input type=text name=nic size=16 ></td></tr>
<tr class=table_row2><Td align=right>Password </td><td> <input type=password name=password size=16 ></td></tr>
<tr class=table_row1><Td align=right valign=top>Server</td><td> <select name=server>
<option value="0" >Normal</option>
<option value="1" >Fast</option>
<option value="2" >Slow</option>
<option value="3" >Ultra</option>
<option value="4" selected>RT</option>
</select><font class=smallfont> <a href=javascript:ch('i.cfm?popup=help&type=server');>What is this <img src=i/help.gif></a>
</td></tr>
<tr class=table_row2><Td align=right> IP </td><td> 69.47.105.149 <font class=smallfont>(United States of America)</font></td></tr>
<tr class=table_row1><td> </td><td> <input type=submit value=" Login " ></td></tr>
</td></tr></table></table>
正如你可以看到有需要的3个输入,在“帝国名”,“密码”,“服务器”,它包括5个选项。假如我从Android GUI收集了相关信息,我将如何通过httpClient将这些数据发送回服务器。任何帮助是极大的赞赏。
代码可能如下所示:
private void postDataToServer() throws UnsupportedEncodingException, IOException {
/*
* Taken from "action" field in the form. This can be absolute address
* so take this into account.
*/
String action = "i.cfm?&1028&p=login&se=4";
/* This the server you want to send info. */
String yourServer = "http://your.server.com/";
/* This form uses "post" method. */
HttpPost post = new HttpPost(yourServer + action);
/* Form parameters. */
List<NameValuePair> params = new ArrayList<NameValuePair>();
/* This is what the user has entered in the corresponding fields. */
String nic = getNic();
String password = getPassword();
String server = getServer();
params.add(new BasicNameValuePair("nic", nic));
params.add(new BasicNameValuePair("password", password));
params.add(new BasicNameValuePair("server", server));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
HttpClient client = new DefaultHttpClient();
post.setEntity(entity);
client.execute(post);
}
也许这page也可能有帮助。
这看起来像我在找什么。我会更多地考虑一下,谢谢。 – 2010-08-24 03:09:36
我知道一个应用程序,其中只包含一个webview来显示移动网站。听起来就像是你应该做的,如果你想尽量减少原生的android编程。
不是我要找的东西,如果您在原始问题中阅读我的评论,我想摆脱网站的原始布局和设计,并在我的内部重新设计Android应用程序,以便我可以以更友好的方式呈现它。 – 2010-08-23 19:29:46
如果您要做的不只是刮一个页面和/或想要开发工具来帮助您,请参阅Web Harvest。它可能具有Android以外的依赖关系,但是如果您需要将其适配到目标平台,则它会受到BSD许可。来源是here。
您解析HTML以为您的应用程序生成UI?这似乎是一个可怕的想法。你究竟在努力完成什么? – noah 2010-08-23 18:48:36
看起来像刮取表单输入的网页并将它们作为Android GUI控件呈现给用户。实际上有趣... – Mchl 2010-08-23 18:56:39
Mchl说什么,我正在刮网页的相关信息。在这个特殊的页面我刮了,该网站显示的IP地址,