Hi, Can anyone show me a few lines of code on how to POST a varible from an applet to a PHP page? My PHP page accepts a varible and writes to a text file. I need to get a variable named "inputString" from the applet to the PHP script. I've tried a few different thing on the web but havent had any luck. Thanks!
Note that your question isn't specific to PHP. I believe that you simply want to POST some text to a web server.
If you were satisfied with a GET request, you could get the applet context and then call one of the showDocument methods, passing in the GET request parameter and value as part of the URL.
If you want to POST data from an applet, after opening a new URLConnection from a URL object, use the OutputStream of that URLConnection to write your data in the format "parameter=value". It's probably a good idea to wrap the OutputStream of the URLConnection in a PrintWriter.
If you can't quite figure things out with the above descriptions, just ask more questions. If you've begun work on some code, please don't hesitate to post it to this forum.
hmm.. adding the lines below under the line "out.close();" causes this to work. Aren't the lines below just reading the text and writing to the Java Console? I thought the lines above did the actual writing to the text file?
BufferedReader in = new BufferedReader( new InputStreamReader( connection.getInputStream()));
while ((inputLine = in.readLine()) != null) System.out.println(inputLine);