Results 1 to 1 of 1

Thread: [JAVA] Post Issues

  1. #1

    Integra's Avatar
    Joined
    Nov 2013
    Posts
    213
    Userbars
    3
    Thanks
    53
    Thanked
    45/32
    DL/UL
    25/0
    Mentioned
    12 times
    Time Online
    4d 18h 34m
    Avg. Time Online
    1m

    [JAVA] Post Issues

    Wondering if anyone may have experienced anything like this before when using (you need an account to see links)

    I'm working on a bit of a project of my own, converting a program I made in VB6 some time ago into Java (The VB6 version still runs fine mind you) in hoping to make it available to my Mac now without all the effort of installing wine and other stuff.

    The issue I seem to have is that the wrapper is only processing a single POST request (e.g. the login request) and all others are seemingly ignored or loading the page but not processing the POST data. Get requests are working fine. The post data is 100% identical to the data which the old program uses and I'm at a bit of a loss with whats going on with it.

    Multidimensional Arrays:
    Code:
    String[][] userInfo = new String[2][5];
            userInfo[0][0] = "action";
            userInfo[1][0] = "login";
            userInfo[0][1] = "username";
            userInfo[1][1] = "XXXXXX";
            userInfo[0][2] = "password";
            userInfo[1][2] = "XXXXXX";
            userInfo[0][3] = "x";
            userInfo[1][3] = "0";
            userInfo[0][4] = "y";
            userInfo[1][4] = "0";
            
            String[][] port1 = new String[2][4];
            port1[0][0] = "radio_goods_2=Buy&goods_sell_2=0&goods_amount_2=";
            port1[1][0] = "0";
            port1[0][1] = "radio_goods_3=Buy&goods_sell_3=0&goods_amount_3=";
            port1[1][1] = "120";
            port1[0][2] = "radio_goods_4=Buy&goods_sell_4=0&goods_amount_4=";
            port1[1][2] = "0";
            port1[0][3] = "&buy.x=0&buy.y=0&buy";
            port1[1][3] = "Buy+and+Sell";
            
            String[][] port2 = new String[2][3];
            port2[0][0] = "radio_goods_3=Buy&goods_sell_3=60&goods_amount_3=";
            port2[1][0] = "120";
            port2[0][1] = "radio_goods_4=Buy&goods_sell_4=0&goods_amount_4=";
            port2[1][1] = "0";
            port2[0][2] = "&buy.x=0&buy.y=0&buy";
            port2[1][2] = "Buy+and+Sell";
    Login Code:
    Code:
    w = new Connection("http://www.game.net");
            
            w.post("/index.php", userInfo);
    Attempted Second Post (Purchase/Sale of Goods):
    Code:
    Pattern cash = Pattern.compile(">\\$(([0-9]+,)*([0-9]+))");
            
            Matcher m1 = cash.matcher(content);
            
            m1.find();
            
            System.out.print("You have $" + m1.group(1) + " on hand!\n");
            
            w.get("/?on=goods_market");
            
            w.post("/?on=goods_market", port1);
    Port1 fails to purchase goods as is required and Port2 fails to sell goods even when you purchase them manually and then try and execute it. I'm assuming it has to be something to do with the way I'm handling the arrays or just something quirky with the wrapper in general. Any help that someone could offer would be greatly appreciated

    ---------- Post added at 03:31 AM ---------- Previous post was at 03:06 AM ----------

    Ok this one might come with a case of I'm a complete retard. Double = and double & in places because I forgot about how the wrapper appends them. Doh!

    Solution Code for the Multidimensional Arrays:
    Code:
    String[][] userInfo = new String[2][5];
            userInfo[0][0] = "action";
            userInfo[1][0] = "login";
            userInfo[0][1] = "username";
            userInfo[1][1] = "XXXXXX";
            userInfo[0][2] = "password";
            userInfo[1][2] = "XXXXXX";
            userInfo[0][3] = "x";
            userInfo[1][3] = "0";
            userInfo[0][4] = "y";
            userInfo[1][4] = "0";
            
    //        for(int i=0; i<5;i++){
    //            System.out.print(userInfo[0][i] + "=" + userInfo[1][i] + "&");
    //        } System.out.print("\n");
            
            String[][] port1 = new String[2][10];
            port1[0][0] = "radio_goods_2";
            port1[1][0] = "Buy";
            port1[0][1] = "goods_sell_2";
            port1[1][1] = "0";
            port1[0][2] = "goods_amount_2";
            port1[1][2] = "0";
            port1[0][3] = "radio_goods_3";
            port1[1][3] = "Buy";
            port1[0][4] = "goods_sell_3";
            port1[1][4] = "0";
            port1[0][5] = "goods_amount_3";
            port1[1][5] = "60";
            port1[0][6] = "radio_goods_4=Buy&goods_sell_4=0&goods_amount_4";
            port1[1][6] = "0";
            port1[0][7] = "buy.x";
            port1[1][7] = "0";
            port1[0][8] = "buy.y";
            port1[1][8] = "0";
            port1[0][9] = "buy";
            port1[1][9] = "Buy+and+Sell";
            
            String[][] port2 = new String[2][9];
            port2[0][0] = "radio_goods_3";
            port2[1][0] = "Sell";
            port2[0][1] = "goods_sell_3";
            port2[1][1] = "60";
            port2[0][2] = "goods_amount_3";
            port2[1][2] = "60";
            port2[0][3] = "radio_goods_4";
            port2[1][3] = "Buy";
            port2[0][4] = "goods_sell_4";
            port2[1][4] = "0";
            port2[0][5] = "goods_amount_4";
            port2[1][5] = "0";
            port2[0][6] = "buy.x";
            port2[1][6] = "0";
            port2[0][7] = "buy.y";
            port2[1][7] = "0";
            port2[0][8] = "buy";
            port2[1][8] = "Buy+and+Sell";
    As you can see I broke the Arrays down further rather than trying to shortcut some strings. It's resolved all issues and the code now executes as expected!
    Last edited by Integra; 08-25-2016 at 12:48 PM. Reason: Editing a minor code muddle up and adding the solution code for all to see.

Posting Permissions

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