尝试自动执行此html表单填充并获取下一页的数据。传递的数据未返回与站点中的内容匹配的方式。
这是代码:

parseSite() throws Exception
{
     Map<String, String> data = new HashMap<>();
  data.put("txtEntryReg1", "35806573CB");
    data.put("txtEntryReg2", "35806573CB");
   data.put("t3", "8/30/2013 2:37:30 AM*");
   data.put("t3", "4:3844: 1NB/9143/21 *");

 data.put("btnSubmit2","+Print+Your+Payment+Invoice");
  //data.putAll("txtEntryReg1=35278160IG&txtEntryReg2=35278160IG&t3=4%3A3623%3A+5NB%2F9143%2F21+*&t3=8%2F30%2F2013+2%3A15%3A24+AM*&btnSubmit2=+Print+Your+Payment+Invoice");
     //data.putAll(data);

     //key1=value1&key2=value2&key3=value3

        doSubmit("http://poters.com.ng/mo/std/acp_slp/1/default.aszp", data);

}

    public void doSubmit(String url, Map<String, String> data) throws Exception {
    URL siteUrl = new URL(url);
    HttpURLConnection conn = (HttpURLConnection) siteUrl.openConnection();
           // conn.setRequestProperty("Cookie", "__utma=244564033.513877751.1371763186.1376824439.1376824439.39; __utmc=244564033; __utmz=244564033.1373732391.30.3.utmcsr=login.lionet50.net|utmccn=(referral)|utmcmd=referral|utmcct=/login");
    conn.setRequestMethod("POST");
    conn.setDoInput(true);
            conn.setDoOutput(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(content)。退货

&t3=4%3A3844%3A+1NB%2F9143%2F21+*&txtEntryReg2=35806573CB&btnSubmit2=%2BPrint%2BYour%2BPayment%2BInvoice

但我要打印
 txtEntryReg1=35278160IG&txtEntryReg2=35278160IG&t3=+%3A3112%3A+8NB%2F0%2F213422*&t3=9%2F1%2F2013+12%3A00%3A17+AM*&btnSubmit=+Create+Payment+Invoice

尝试更改data.put(...,...)顺序,但仍然无法正常工作。
有人请帮助

最佳答案

这是因为HashMap不会保留记录的插入顺序。您可以改用LinkedHashMap

但是,为什么顺序很重要?

关于java - Java HTML表单处理未返回输入的数据字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18560200/

10-12 23:55