通过httpclient android发送html命令

发布于 09-15 11:04 字数 1948 浏览 8 评论 0原文

我试图通过解析网页中的相关数据,然后允许用户将数据发送回服务器,将 Web 界面转换为 Android 界面。使用简单的 HttpClient 代码,我成功地获取了网页,然后解析了必要的信息。我不熟悉发送数据回来,所以,我希望有人能提供一些线索。以下是登录页面的相关 HTML 代码。

<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>&nbsp;Empire Name&nbsp;</td><td>&nbsp;<input type=text name=nic size=16 ></td></tr>
<tr class=table_row2><Td align=right>Password&nbsp;</td><td>&nbsp;<input type=password name=password size=16 ></td></tr>

<tr class=table_row1><Td align=right valign=top>Server</td><td>&nbsp;<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>&nbsp;IP&nbsp;</td><td>&nbsp;69.47.105.149 <font class=smallfont>(United States of America)</font></td></tr>
<tr class=table_row1><td>&nbsp;</td><td>&nbsp;<input type=submit value="  Login  " ></td></tr>

</td></tr></table></table>

正如您所看到的,需要 3 个输入,“帝国名称”、“密码”和“服务器”,其中包含 5 个选项。假设我已经从 Android GUI 中收集了相关信息,我将如何通过 httpClient 将这些数据发送回服务器。非常感谢任何帮助。

I'm attempting to turn a web interface into an Android one by parsing the web page for relevant data and then allowing the user to send back data to the server. Using simple HttpClient code I have managed to get the web page and then parse the necessary information. I'm unfamiliar with sending data back, so, I'm hoping someone can shed some light. Here's the relevant HTML code from the login page.

<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>

As you can see there are 3 inputs needed, the "Empire Name", "Password", and the "Server" which consist of 5 options. How would I go about sending this data back to the server over httpClient, assuming that I have gathered the relevant information form my Android GUI. Any help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一抹苦笑 2024-09-22 11:04:46

如果您要做的不仅仅是抓取一页和/或需要开发工具来帮助您,请查看 网络采集。它可能具有 Android 提供之外的依赖项,但如果您必须将其适应目标平台,则它受 BSD 许可。来源位于此处

If you're going to do more than scrape one page and/or want a development tool to help you, take a look at Web Harvest. It may have dependencies outside of what Android provides, but it is under BSD license should you have to adapt it to the target platform. Source is here.

丘比特射中我 2024-09-22 11:04:46

代码可能如下所示:

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);
}

也许这个页面也可能有所帮助。

The code may look like the following:

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);
}

Maybe this page also may help.

金兰素衣 2024-09-22 11:04:46

我知道一个应用程序仅包含一个网络视图来显示移动网站。听起来这就是你应该做的,如果你想最小化原生 android 编程。

I know a application which contains only a webview to display the mobile website. Sounds like thats what you should do, if you want to minimize the native android programming.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文