Network Programming :: Projects :: Form Poster
Problem
Create a program that allows the user to enter their name as well as other information of your choice. The information should then be processed in a PHP file and the results sent back to the Java program to be displayed. You will need to follow these steps:
- Decide what name-value pairs you will send to the PHP file.
- Write the PHP file that will accept and process the request. You can check out this PHP lesson for basic details.
- Create a query string in your Java program that looks something like this:
name1=value1&name2=value2
Pass each name and value in the query string to the URLEncoder.encode() method before adding it to the query string. - Open a URLConnection to the URL of the program that will accept the data.
- Set doOutput to true by calling the setDoOutput(true) mutator to use a POST request.
- Write the query string onto the URLConnection's OutputStream.
- Close the URLConnection's OutputStream.
- Read the server response from the URLConnection's InputStream.
To upload your PHP file you can follow the instructions in this HTML lesson.