Bob the Builder Posted April 5, 2010 Share Posted April 5, 2010 Hello, I recently started writing my own web server in Java. I have PHP working, but I can't figure out how to pass cookies to the CGI. Here's a quick snippet of the general code that I'm using (and then reading the output and writing it to the browser): Runtime.getRuntime().exec("php-cgi C:\test.php test=1 test2=2"); That works fine for arguments, but I can't seem to find a way to pass cookies that were read from the HTTP request header. Does anyone know if it's possible, and if so how? Thanks. Quote Link to comment Share on other sites More sharing options...
Bob the Builder Posted April 7, 2010 Author Share Posted April 7, 2010 I've figured it out; I can pass them to the CGI process using environmental variables. ArrayList<String> envp = new ArrayList<String>(); for (Map.Entry<String, String> entry : System.getenv().entrySet()) { // Add the computer set variables. envp.add(entry.getKey() + "=" + entry.getValue()); } envp.add("HTTP_KEEP_ALIVE=" + httpRequest.getHeaderProperty("Keep-Alive")); envp.add("HTTP_CONNECTION=" + httpRequest.getHeaderProperty("Connection")); envp.add("HTTP_COOKIE=" + httpRequest.getHeaderProperty("Cookie")); envp.add("HTTP_CACHE_CONTROL=" + httpRequest.getHeaderProperty("Cache-Control")); Process process = Runtime.getRuntime().exec(command, envp.toArray(new String[envp.size()])); // Execute php-cgi.exe Which works great. That said, I have a new problem: passing POST. I've tried multiple different names, such as POST, HTTP_POST, HTTP_POST_VARS, etc, but none add to $_POST. Does anyone know what environmental variable PHP uses for POST? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.