the puzzles will now accept HTTP POST requests for automated problem submissions. use the same vars as for the GETs. (this first cropped up with Mortal Coil, level 437 -- nasty one.)
adum
submission with POST
-
- Posts: 2
- Joined: Fri Jan 22, 2010 5:53 pm
How would you do a POST request in java? I'm at level 92 of crossflip, and my code no longer seems to work:
URL u;
u = new URL("http://www.hacker.org/cross/index.php?name=" + $name + "&password=" + $password + "&sol=" + sol);
InputStream is = u.openStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = in.readLine()) != null)
{
System.out.println(line);
}
is.close();
URL u;
u = new URL("http://www.hacker.org/cross/index.php?name=" + $name + "&password=" + $password + "&sol=" + sol);
InputStream is = u.openStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = in.readLine()) != null)
{
System.out.println(line);
}
is.close();
http://www.exampledepot.com/egs/java.net/post.html
that should help
that should help
-
- Posts: 33
- Joined: Sat Aug 13, 2011 2:13 pm
after many trys i got post method working
this is the solution posting section of the solver code in Java. it should be easy to adapt this to any game here, just change the url address and the writer.write line with '&' separated key/value pairs like a get line would have. i tried other examples but seems the page here was ignoring me till i added the content-type.
Code: Select all
public boolean solve() throws Exception {
URL u;
String path = findSolutionPath();
System.out.println("solved at (" + startX + ", " + startY
+ ") : " + path);
String enc="UTF-8";
u = new URL("http://www.hacker.org:80/coil/index.php");
URLConnection conn=u.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
OutputStreamWriter writer=new
OutputStreamWriter(conn.getOutputStream());
writer.write("name=" + URLEncoder.encode(name, enc) +
"&password=" + URLEncoder.encode(pw, enc) +
"&path=" + path + "&x=" + startX + "&y=" + startY);
writer.flush();
BufferedReader rd = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
rd.readLine();
writer.close();
rd.close();
return false;
}