Problem sending POST request with Java..
Hey there, for some reason my post request meaning to be: http://myurl.net/index.php?nmb=random_chars_etc wont work, here's my code:
Code Java:
import java.util.UUID;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class Main{
private static String uuid = UUID.randomUUID().toString().replaceAll("-", "");
public static void main(String[] args)throws Exception{
String data = URLEncoder.encode("nmb", "UTF-8") + "=" + URLEncoder.encode("test", "UTF-8");
URL url = new URL("http://myurl.net");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
wr.close();
rd.close();
}
}
It definatlely reaches my page where I process the POST with php, however the UUID isnt sent over the url for some reason, a bit stuck..
Re: Problem sending POST request with Java..
Quote:
Originally Posted by
lost
however the UUID isnt sent over the url for some reason
Please define what you mean by the UUID isn't sent. Does this mean the PHP page does not retrieve the 'nmb' value? In the php page, are you using $_GET, $_POST, $_REQUEST?
Re: Problem sending POST request with Java..
As in the UUID isnt getting sent over the url for instance it should be like:
http://myurl.net/index.php?nmb=<UUID HERE>
but instead its just not being sent, I use $UID = $_GET['nmb']; to grab the UUID
When I test my php page with a url say like:
http://myurl.net/index.php?numb=randomblahblah
^ That works, so its not the PHP
Re: Problem sending POST request with Java..
But that is the problem. $_GET retrieves the value using 'get' (values in the url), $_POST retrieves the value using 'post' (values written within the message body), and $_REQUEST retrieves either (and then some). Change the php to post or request and see what happens