Java 如何从android发布表单数据?
我想使用Android java“模拟”浏览器和登录后数据。我试过这个 但我失败了 网址:http://192.168.254.34/Control?id=1000 以下是html源代码:Java 如何从android发布表单数据?,java,android,http,browser,Java,Android,Http,Browser,我想使用Android java“模拟”浏览器和登录后数据。我试过这个 但我失败了 网址:http://192.168.254.34/Control?id=1000 以下是html源代码: <html><head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>欢迎使用WLAN无线宽带</title> <style>&l
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>欢迎使用WLAN无线宽带</title>
<style><!--
a {text-decoration: none}
.f1 { font-size: 10.5pt; font-family: Verdana; line-height: 12pt }
.f2 { font-size: 8pt; font-family: Verdana; line-height: 12pt }
.btn {
BORDER-LEFT: #7b9ebd 1px solid;
BORDER-RIGHT: #7b9ebd 1px solid;
BORDER-TOP: #7b9ebd 1px solid;
BORDER-BOTTOM: #7b9ebd 1px solid;
PADDING-LEFT: 2px;
PADDING-RIGHT: 2px;
PADDING-TOP: 2px;
FONT-SIZE: 10.5pt;
CURSOR: hand;
COLOR: black;
FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
}
-->
</style>
<base href="http://192.168.254.34/pageset/131/PDA/">
</head><body topmargin="0" leftmargin="0">
<!-- 本地动态密码开始-->
<script>
function submitform2(){
if (form1.strAccount.value==""){
alert("请填入用户名!");
return;
}
form2.num.value=form1.strAccount.value;
form2.submit();
}
</script>
<iframe scr="about:blank" width="0" height="0" name="a"></iframe>
<FORM name="form2" method=post action="http://218.204.223.213:8080/cmpp/service.do?id=newuser" target="a">
<input size=12 type=hidden name="num" maxlength=26 style="border:1px solid #999999; FONT-SIZE: 10.5pt; BACKGROUND: #ffffff; COLOR: #333399; FONT-FAMILY: verdana; 1px:" size="14"></td>
<INPUT value="172.31.18.199" type=hidden name=ip>
</FORM>
<!-- 本地动态密码结束 --><form name=form1 method=post action="/Control?id=2000">
<center>
<table width=600 border=0 height=800>
<tr>
<td height=800>
<div align=center>
<center>
<table width=600 border=0 height=800 bgcolor=#FFFFFF cellspacing=0 cellpadding=0 style="border-collapse: collapse" bordercolor=#111111>
<tr>
<td height=800 width=600 background="a02.jpg" align="center">
<table border="0" width="288" cellspacing="0" cellpadding="0" height="97%">
<tr>
<td height="82" colspan="2">
<p align="center" class="f1">
</td>
</tr>
<tr>
<td height="295" align="center" colspan="2">
<table border="0" width="104%" cellspacing="0" cellpadding="0" height="106%">
<tr>
<td height="148" colspan="2">
<p align="center">
<font color="#333399" style="font-size: 10.5pt">
欢迎使用WLAN无线登陆页面</font></td>
</tr>
<tr>
<td width="32%" height="33" align="right" class="f1">
用户帐号</td>
<td height="33" width="68%">
<input name=strAccount maxlength=26 style="border:1px solid #999999; FONT-SIZE: 10.5pt; BACKGROUND: #ffffff; COLOR: #333399; FONT-FAMILY: verdana; 1px:" size="21"></td>
</tr>
<tr>
<td width="32%" align="right" class="f1">用户密码</td>
<td width="68%">
<input type=password name=strPassword maxlength=16 style="border:1px solid #999999; FONT-SIZE: 10.5pt; BACKGROUND: #ffffff; COLOR: #333399; FONT-FAMILY: verdana; 1px:" size="21"></td>
</tr>
<tr>
<td height="96" colspan="2" align="left">
<p align="center">
<input type="button" value="登 录" width="86" height="23" name="I1" onclick="javascript:form1.submit();" class="btn">
<input type="reset" value="重 置" width="86" height="23" name="I2" class="btn"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="f1" width="255">
<p align="center"> </td>
<td class="f1" width="33">
</td>
</tr>
<tr>
<td class="f1" height="91" width="255">
<p align="center" class="f1">
</td>
<td class="f1" height="91" width="33">
</td>
</tr>
<tr>
<td height="108" colspan="2">
<p align="center">
<br>
</td>
</tr>
</table>
</td>
</tr>
</table></center></div></td></tr></table></center></form></body></html>
任何人都知道如何使用HttpClient发布登录数据。我可以发布和处理身份验证。Doc我是这样做的:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("www.server.com/dologin.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", "KennyStarfighter");
nameValuePairs.add(new BasicNameValuePair("password", "SecretPassword");
nameValuePairs.add(new BasicNameValuePair("redirect", "?controller=login&view=loggedonpage"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity he = response.getEntity();
@user883883可能重复-您需要在网页上为POST命令输入正确的登录字段名称。我示例中的名称是任意的。此外,根据您的实现,您可能不需要登录。这完全取决于你想做什么。
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("www.server.com/dologin.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", "KennyStarfighter");
nameValuePairs.add(new BasicNameValuePair("password", "SecretPassword");
nameValuePairs.add(new BasicNameValuePair("redirect", "?controller=login&view=loggedonpage"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity he = response.getEntity();
xmlReader.parse(new InputSource(he.getContent()));