尝试自动填充此 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(...,...) 顺序,但仍然没有任何效果。有人请帮忙