-
Java - Sending POST data
I probably won't get help here but maybe it's worth the try...
I'm trying to deliver simple post data to a form.
Data: log=admin&pwd=<<PASSWORD>>
If the <<PASSWORD>> value is correct, HTTP will return a 302 response code, otherwise it will return a 200 response code.
Code:
import java.io.*;
import java.util.*;
import java.net.*;
public class JiggaPlz
{
public static void main(String[] args) throws IOException, MalformedURLException, SocketException
{
URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream input;
url = new URL ("http://jiggaplz.thesarcasm.com/wp-login.php");
urlConn = url.openConnection();
urlConn.setDoInput (true);
urlConn.setDoOutput (true);
urlConn.setUseCaches (false);
urlConn.setRequestProperty
("Content-Type", "application/x-www-form-urlencoded");
// Send POST output.
printout = new DataOutputStream (urlConn.getOutputStream ());
String content =
"log=" + URLEncoder.encode ("admin") +
"&pwd=" + URLEncoder.encode ("correctPasswordHere");
printout.writeBytes (content);
printout.flush ();
printout.close ();
// Get response data.
input = new DataInputStream (urlConn.getInputStream ());
String str;
while (null != ((str = input.readLine())))
{
System.out.println (str);
}
input.close ();
}
}
-
hey sry i just started working with javascript at my job so i prolly wont be of much help..
what i know is that to send a form, you will need server-side scripting with the whole sending form thing. our host uses 'flexmail'.
erm, thats prolly not what you are looking for. thats all i know other than a few scripts for dynamic form fields (some of which i am still learning)
-
Nevermind, I got it.
Code:
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.*;
import java.io.*;
public class WPCrack
{
public static void main(String[] args) throws IOException
{
}
public static int wpAttempt(String url, String user, String pass)
{
// Create an instance of HttpClient.
HttpClient client = new HttpClient();
// Create a method instance.
PostMethod post = new PostMethod(url);
NameValuePair[] data = {
new NameValuePair("log", user),
new NameValuePair("pwd", pass)
};
post.setRequestBody(data);
// Provide custom retry handler is necessary
post.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(post);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + post.getStatusLine());
}
// Read the response body.
byte[] responseBody = post.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
post.releaseConnection();
}
}
}