How to get "post" data?

Discussion in 'PHP' started by mculp, May 24, 2007.

  1. #1
    I have some java code that opens a connection to a website (which is php based) and writes a byte array to the connection via an outputStream. The connection has been set up as a POST.
    Now the problem comes with the php code. All I want it to do is take the byte array that its been given, and output the stuff in the array. Normally I'd just grab the data as if it were a form, but I'm trying to use a content type of "application/octet-stream". Any ideas as to how to go about doing this??
    Thanks.
     
    mculp, May 24, 2007 IP
  2. tinkerbox

    tinkerbox Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I no nothing about java. But i know javascript.
    But if you want to grap value from POST:
    $value_in_array = $_POST['array'];

    check tutorial here:
    http://www.tizag.com/phpT/postget.php
     
    tinkerbox, May 24, 2007 IP
  3. mculp

    mculp Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That would definately be the way that it would be done if we were dealing with a form, but the data isn't being passed in as a form; its simply an array of bytes (that has been generated by grabbing the bytes from a string). So in the header of the POST, it has the content type listed as a stream of bytes, rather than form data. Because of this, it doesn't have any names for variables, so it can't say "go grab this variable from the post".
     
    mculp, May 24, 2007 IP
  4. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #4
    explain with code.
     
    coderbari, May 24, 2007 IP
  5. tinkerbox

    tinkerbox Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
  6. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can access the raw post data with code like this:

    <html>
    <body>
    <pre>
    <?php
      $rawpost = file_get_contents ("php://input");
      var_dump ($rawpost);
    ?>
    </pre>
    </body>
    </html>
    PHP:
    See what you get when you point your Java program to that script and you should have some ideas how to extract the byte array.
     
    lemaitre, May 24, 2007 IP
  7. mculp

    mculp Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I daresay that worked quite nicely. Thank you!
     
    mculp, May 25, 2007 IP