现在需要用Java向IIS服务器的某个aspx页面发出一个HTTP的请求,采用POST方式,里面带两个参数(用户名、密码)然后在aspx页面的后台类中取出参数,能否实现。Request请求要求和以下HTML提交的请求一致。
<form action="http://localhost/test/example.aspx" method="POST">
<input type="text" size="10" value="username" name="username">
<input type="text" size="10" value="password" name="password">
<input type=submit value="POST方式">
</form>
<form action="http://localhost/test/example.aspx" method="POST">
<input type="text" size="10" value="username" name="username">
<input type="text" size="10" value="password" name="password">
<input type=submit value="POST方式">
</form>
<body>
<form name="ctrl2" method="POST" action="MyLinkButton.aspx" id="ctrl2">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="dDwtMjI1NTgwNDE2Ozs+eIZ+AfRvoCj1nWimbh+zPv/rKNg=" />
Here is the custom link button.<br>
<a id ="Link" href="javascript:__doPostBack('Link','')"> Link</a>
<br><br>
<input name="TextBox" type="text" value="Click the link" id="TextBox" style="background-color:Cyan;width:200px;" />
<br>
<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform = document.ctrl2
theform.__EVENTTARGET.value = eventTarget
theform.__EVENTARGUMENT.value = eventArgument
theform.submit()
}
// -->
</script>
</form>
</body>
</html>
aspxstring a = Request.Form["username"].Value;
现在已经知道java中的HttpURLConnection类可以实现发送Post请求,可带参数一直没有成功。不过如果用写流的方法则可以实现。(问题可能放错地方了,应该放到Java版中去)