如何调试此Java代码 - POST请求

时间:2014-09-15 18:15:08

标签: java html forms post

我有以下代码,这是我尝试填写POST主体并提交。

//get myIP as var via InetAddress and getHostAddress

String query =  URLEncoder.encode("ip!0", "UTF-8") +"=" + URLEncoder.encode(myIP, "UTF-8")
+ "&"+ URLEncoder.encode("abuse_address!0", "UTF-8") + "=" + URLEncoder.encode("abuse@123test", "UTF-8")
+ "&" +URLEncoder.encode("admin_username!0", "UTF-8") + " =" + URLEncoder.encode("admin", "UTF-8") 
+ "&" +URLEncoder.encode("admin_password!0", "UTF-8") + "="+ URLEncoder.encode("pass", "UTF-8");
URL url = new URL("http://xx.x.x.xx/index.ws3?25334cvvssd522afmkkllmk"); // url has a unique hash

URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(
urlConnection.getOutputStream());
out.write(query);
out.flush();
BufferedReader in = new BufferedReader(
new InputStreamReader(urlConnection.getInputStream()));
String line = null;
while ((line = in.readLine()) != null)
{
    System.out.println(line);
}
out.close();
in.close();

现在当我运行它时,它没有发布,因为新条目没有显示在网页上。打印输入流的每一行的while循环与页面源基本相似。我会把它放在这里:

<html>
        <head>
    //scripts
<body>
</table><br>
    <INPUT type="submit" name="submit" value="hosts_save"> <INPUT type="button" ONCLICK="history.go(-1)" name="cancel" value="cancel"></input>
    </form>

    <form action="/index.ws3?25334cvvssd522afmkkllmk" method="post">
    <table border="1" width="100%">
        <THEAD>
<TH>host_id</TH><TH>ip</TH><TH>abuse_address</TH><TH>admin_username</TH><TH>admin_password</TH></THEAD>
<tr>
            <td>-</td>
            <td><INPUT type="text" name="ip!0" value="new ip"></input></td>
            <td><INPUT type="text" size="45" maxlength="45" name="abuse_address!0" value="new address"></input></td>
            <td><INPUT type="text" size="45" maxlength="100" name="admin_username!0" value="new username"></input></td>
            <td><INPUT type="password" size="45" maxlength="45" name="admin_password!0" value="new password"></input></td>
        </tr>

    </table><br>
        <INPUT type="submit" name="submit" value="hosts_save"> <INPUT type="button" ONCLICK="history.go(-1)" name="cancel" value="cancel"></input>
    </form>

    </body></html>

在这个回复正文中,我是否应该看到像这样的“滥用@ 123test”和“admin”等? :

<INPUT type="text" size="45" maxlength="100" name="admin_username!0" value="admin">admin</input>

如何查看历史记录以查看失败的位置?它可能会失败几件事。它无法击中正确的页面,它可能传递错误的参数...我怎么能告诉任何正在发生的事情,以便推进我成功发布?

0 个答案:

没有答案