title: unable to submit form using java URLConnection
body: <p>I'm trying to submit a form using JAVA URLConnection class but I keep on getting back a page with:</p>
  
  <pre><code>meta http-equiv="refresh" content="1;url=/nidp/jsp/err.jsp?sid=0?error=Required+JavaScript+support+is+not+available.&amp;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."&gt;
  </code></pre>
  
  <p>I suspect it has something to do with either cookies or a javascript manipulation I don't take under consideration when I'm sending the POST request.</p>
  
  <p>Since it is a https page, I couldn't look at the post request on wireshark, So I don't really know how the POST packet leaves the eclipse.
  I do know how the IE POST packet looks like, since I used the developer's tools to see the request.</p>
  
  <p>And now for the form:</p>
  
  <pre><code>&lt;form name="frmlogin" action="Login_Chk.aspx?rk=" method="post" onsubmit='return chk_form()' autoComplete="off"&gt;
      &lt;input type="text" name="txtUser" Class="freeinputl" onKeyPress="return chkAlpha(event,'eng');" /&gt;
      &lt;input type="text" name="txtId" Class="freeinputl" onKeyPress="return chkDigits(event,'');" /&gt;
      &lt;inputtype="password" name="txtPass" class="freeinputl" onKeyPress="return chkAlpha(event,'eng');" /&gt;
      &lt;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'"&gt;
      &lt;input TYPE="hidden" name="javas" value="0"&gt;
      &lt;input TYPE="hidden" name="src" value=""&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>the javascripts (on the same source):</p>
  
  <pre><code>&lt;script type="text/javascript" src="/Js/Global.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/Form.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  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);
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>and my java code:</p>
  
  <pre><code>public static void doSubmit(String url, Map&lt;String, String&gt; 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 += "&amp;";
          }
          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&lt;String, String&gt; data = new HashMap&lt;String, String&gt;();
      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);
  </code></pre>
  
  <p>Thanks!</p>