我想用java编写一个应用程序来将POST方法发送到URL。问题是没有动作字符串。我编写了下面的java代码以编程方式登录到该站点,但它不起作用。任何信息都可以提供帮助。
这是表格和验证:
<form method="post" action="" name="login_form" id="login_form" onSubmit="return ValidateForm();">
<input type="text" name="email" id="login_email" value="" class="txt" /></td>
<input type="password" name="password" id="login_password" value="" class="txt" /></td>
<select name="lang" id="lang">
<option value="en" label="English" selected="selected">English</option>
<option value="Fr" label="French">French</option>
</select>
<button type="submit">Login</button>
</form>
function ValidateForm(){
var emailID=document.login_form.email
var ps=document.login_form.password
if ((emailID.value==null)||(emailID.value=="")){
alert("Please enter email address");
emailID.focus();
return false
}
if (ps.value==''){
ps.focus();
alert("Please enter password");
return false
}
return true
}
这是我的客户端应用程序,它使用org.apache.http并用java编写:
HttpPost hpost = new HttpPost("http://something.com/");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("email", "myemail@yahoo.com"));
nvps.add(new BasicNameValuePair("password", "blahblahblah"));
nvps.add(new BasicNameValuePair("lang", "en"));
hpost.setEntity(new UrlEncodedFormEntity(nvps,Consts.UTF_8));
Myresponse = Myhttpclient.execute(hpost,MyHttpContext);