如何使用httpurlconnection提交表单?

时间:2014-04-07 16:31:15

标签: javascript html forms httpurlconnection

我想提交的表格格式如下

<form class=loginForm name="LoginForm" onSubmit="return loginSubmit();"
    method="post">
    <fieldset>
    <ol>



<li><span class="instruction">Please login with your User Name and Password.</span></li>

        <li><a tabIndex=2 target="_blank"
            href="/portal/site/login/en-gb/help.html"
            class="assistance redArrow">Need help with logging in?</a>
        </li>
        <li><label for="username">User Name</label> <input tabIndex=3
            class="authInput" type="text" id="username" name="username"
            autocomplete="off" class="authInput" /></li>
        <li><label for="password">Password</label> <input tabIndex=4
            type="password" id="password" name="password" autocomplete="off"
            class="authInput" /></li>

        <li class="persist"><label for="secureComputer"> <input type="checkbox"
                value="1" tabIndex="5" name="rememberMe" id="secureComputer"
                 /><span style="padding-left:10px;">I am on a secure computer.</span>
                <br><span style="margin-left: 23px; font-size: 10px;">(Only check if this computer is secure and is only used by you.)</span>
        </label></li>
    </ol>   


                    <a tabIndex=6
            href="/IDM/pwdservice?a=fp"
            class="assistance redArrow">Forgotten your Password?</a><br>

                <input tabIndex=7 type="submit"
            value="Login"
            class="redBtn"/><br>

</fieldset>
</form>



<form   name="Login"  onsubmit="" action="/IDM/UI/Login"  method="post" style="display:none">
    <input type="hidden" name="IDToken1" value="">
    <input type="hidden" name="IDToken2" value="">  
    <input type="hidden" name="IDButton" value="Log In">
    <input type="hidden" name="gotoOnFail" value="">
    <input type="hidden" name="encoded" value="true">
    <input type="hidden" name="service" value="">
    <input type="hidden" name="stepUp" value="N">
    <input type="hidden" name="currLang" value="en">
    <input type="hidden" name="gx_charset" value="UTF-8">
    <input type="hidden" name="rememberMe" value="N">

我试图以与提到的here相同的方式继续前进。以下是我的处理方式:

 URL server = new URL(url);
HttpsURLConnection urlConn = (HttpsURLConnection) server.openConnection();
        urlConn.setRequestMethod("POST");
        urlConn.setDoOutput(true);
        urlConn.setDoInput(true);
        urlConn.setUseCaches(false);
        DataOutputStream printout = new DataOutputStream (urlConn.getOutputStream());
        if (parameters != null)
            printout.writeBytes (parameters);
        printout.flush();
        printout.close();

其中parameters的格式为name1=value1&name2=value2.....&username=uname&password=pwd

但问题是我想为登录(tabindex = 7)添加参数名称及其值,如上面提到的link所示,输入也是如此没有名字只有它的价值?

有没有其他方式提交此类表单登录网站? HTML页面上有 loginSubmit 函数,有没有办法将其用于urlConn

0 个答案:

没有答案