+ Follow This Topic
Results 1 to 3 of 3

Thread: Java - Sending POST data

  1. #1
    King Zarathu's Avatar
    King Zarathu Guest

    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 ();
    
    	    
    	
    	}
        }

  2. #2
    lilwing89's Avatar
    lilwing89 Guest
    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)

  3. #3
    King Zarathu's Avatar
    King Zarathu Guest
    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();
    	    }
    	    
    	    
    	}
    }

Similar Threads

  1. Replies: 0
    Last Post: 30-09-09, 01:02 PM
  2. Is he sending signals?
    By babygirl in forum Love Advice forum
    Replies: 6
    Last Post: 07-09-09, 11:37 PM
  3. Anyone know Java?
    By Mish in forum Off Topic Discussion
    Replies: 4
    Last Post: 26-05-09, 07:49 AM
  4. java junkies
    By misombra in forum Off Topic Discussion
    Replies: 1
    Last Post: 08-02-05, 12:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •