Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用java URL连接提交表单_Java_Javascript_Html_Post_Httpsurlconnection - Fatal编程技术网

无法使用java URL连接提交表单

无法使用java URL连接提交表单,java,javascript,html,post,httpsurlconnection,Java,Javascript,Html,Post,Httpsurlconnection,我正在尝试使用JAVA URLConnection类提交表单,但我不断返回一个包含以下内容的页面: meta http-equiv="refresh" content="1;url=/nidp/jsp/err.jsp?sid=0?error=Required+JavaScript+support+is+not+available.&cause=JavaScript+has+been+disabled+or+the+browse+does+not+support+JavaScript.+U

我正在尝试使用JAVA URLConnection类提交表单,但我不断返回一个包含以下内容的页面:

meta http-equiv="refresh" content="1;url=/nidp/jsp/err.jsp?sid=0?error=Required+JavaScript+support+is+not+available.&cause=JavaScript+has+been+disabled+or+the+browse+does+not+support+JavaScript.+Use+a+JavaScript+capable+browser+and%2For+enable+JavaScript+support+in+the+browser.">
我怀疑这与cookies或javascript操作有关,我在发送POST请求时没有考虑到这一点

因为它是一个https页面,所以我无法查看wireshark上的post请求,所以我不知道post数据包是如何离开eclipse的。 我确实知道IE POST包的样子,因为我使用了开发人员的工具来查看请求

现在是表格:

<form name="frmlogin" action="Login_Chk.aspx?rk=" method="post" onsubmit='return chk_form()' autoComplete="off">
    <input type="text" name="txtUser" Class="freeinputl" onKeyPress="return chkAlpha(event,'eng');" />
    <input type="text" name="txtId" Class="freeinputl" onKeyPress="return chkDigits(event,'');" />
    <inputtype="password" name="txtPass" class="freeinputl" onKeyPress="return chkAlpha(event,'eng');" />
    <input type='image' name='btnishur' id='btnishur'  tabindex=99 class='hideprint' align=absmiddle src='ok.gif'  onmouseover="this.src='ok_over.gif'" onmouseout="this.src='ok.gif'">
    <input TYPE="hidden" name="javas" value="0">
    <input TYPE="hidden" name="src" value="">
</form>
同一源上的Java脚本:

<script type="text/javascript" src="/Js/Global.js"></script>
<script type="text/javascript" src="js/Form.js"></script>
<script type="text/javascript">
var sw_caps=false;
function setFocus()
{ 
 obj=document.frmlogin;  
 obj.txtUser.focus();
}
function chk_form()
{
 obj=document.forms[0];
 if(!chkTextField(obj.txtUser,'Username','yes',2,'','')){return false;}
 if(!chkTextField(obj.txtId,'ID','yes',1,'D','')){return false;}
 if(!chkTextField(obj.txtPass,'pass','yes',1,'','')){return false;}
 return chkFormEndShort(obj);
}
</script>
和我的java代码:

public static void doSubmit(String url, Map<String, String> data) throws Exception {
    URL siteUrl = new URL(url);
    HttpsURLConnection conn = (HttpsURLConnection) siteUrl.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);
    conn.setDoInput(true);

    DataOutputStream out = new DataOutputStream(conn.getOutputStream());

    Set keys = data.keySet();
    Iterator keyIter = keys.iterator();
    String content = "";
    for(int i=0; keyIter.hasNext(); i++) {
        Object key = keyIter.next();
        if(i!=0) {
            content += "&";
        }
        content += key + "=" + URLEncoder.encode(data.get(key), "UTF-8");
    }
    System.out.println(content);
    out.writeBytes(content);
    out.flush();
    out.close();
    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line = "";
    while((line=in.readLine())!=null) {
        System.out.println(line);
    }
    in.close();
    System.out.println("protocol = " + siteUrl.getProtocol());
}

public static void main(String[] args) throws Exception {
    Map<String, String> data = new HashMap<String, String>();
    data.put("user", "XYZ");
    data.put("pass", "xyz");
    data.put("id", "123456789");
    data.put("src", "");
    data.put("javas", "1");
    data.put("btnishur.x", "0");
    data.put("btnishur.y", "0");
    doSubmit("https://www.x.y/Login_Chk.aspx?rk=HTTP/1.1", data);

谢谢

我相信在提交表单时,提交按钮的值会被包括在内,因为它被认为是一个应用程序。也许把它包括在你的地图上会有帮助吗?没有提交按钮。图像是“提交按钮”。你也可以看到我把这个btnishur.x和.y包含在内。我看到IE添加了它们:请求体-txtser=XYZ&txtId=30411111&txtPass=N4c&javas=1&src=&btnishur.x=0&btnishur.y=0