1

我想用 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);
4

0 回答 0