Hi,
I'm having problems forming an http request in java.
Here's what I do:
I've got a simple php (java.php) file on my apache server, here's it's code:
If I do this request:<?php $post_var = $_POST['post_var']; if (!isset($post_var)) $post_var = $_GET['post_var']; if ($post_var == 1) echo "works"; else echo $post_var . ": post_var"; ?>from browser, I get "works" output. The same if I send POST or GET request from a ActionScript 3 client.http://warfarex.com/java.php?post_var=1
But Java keeps on giving me this:
So, as you can see, it's the output of an "else" block.: post_var
And finally, here is the Java code I use to make these requests:
String request = "?post_var=1"; URL url = new URL("http://warfarex.com/java.php"); URLConnection connection = url.openConnection(); connection.setDoOutput(true); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(connection.getOutputStream()); outputStreamWriter.write(request); outputStreamWriter.flush(); System.out.println(request); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String response; while ((response = bufferedReader.readLine()) != null) { System.out.println(response); } outputStreamWriter.close(); bufferedReader.close();
What's wrong with this code?
regards, Konstantin.