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.
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
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".
Im not java programmer, so cant help much. But i did some googling. This might help you: http://php-java-bridge.sourceforge.net/pjb/ http://java.sys-con.com/read/36044.htm http://faqs.javabeat.net/servlet/java-servlets-interview-questions-faqs-4.php
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.