Smart CODE | |
Your on-line guide to the generated code |
A web browser will take the FORM elements in the HTML form, convert any text into an encoded format, and send the data as name=value pairs, name corresponding to the name tag of the FORM element, and value, its setting/data.
It may also send content headers to the server identifying itself, the URL of the form, and other details. Some servers may take note of this information, and may, for example respond differently to Netscape compared to Internet Explorer. Sophisticated server programs may even refuse to reply to clients that they don't recognise.
The easiest way to find out how the default HTML form interface interacts with the server is to monitor the connection. The following java program will run a simple server that just echoes what is sent to it. To find out what gets sent when you press a form's submit button:
This example puts the query in the URL itself and uses the GET method. This can be imitated by setting the "Url Data" field in the Internet Smart Code customizer dialog to be a function, and programming that function to return the appropriate query string. This section concentrates on forms with potentially more than 128 bytes of query data - which will be handled through the POST method - the data being sent on the output stream after the content headers.
Here is the code for the Java monitor program. Cut it to a file called Server.java, to compile and run it.
import java.net.*;
import java.io.*;
public class Server extends Thread {
ServerSocket ss = null;
public Server() {
try {
ss = new ServerSocket(2000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Listening on port 2000");
this.start();
}
public void run() {
try {
while(true) {
Socket client = ss.accept();
handleClient( client);
}
} catch (IOException e) {
System.out.println("Exception while listening for connection");
}
}
void handleClient( Socket s)
throws IOException
{
DataInputStream in = new DataInputStream(s.getInputStream());
while (true) {
String line = in.readLine();
if (line == null)
return;
System.out.println( line);
}
}
public static void main(String []args) {
Server s = new Server();
}
}
Changing Request Headers | ||
---|---|---|
Language | Usage | |
C |
|
|
C++ |
|
|
Java |
|
Sending data to the connection's OutputStream | ||
---|---|---|
Language | Usage | |
C |
|
|
C++ |
|
|
Java |
|
POSTing group data to a web server | ||
---|---|---|
Language | Usage | |
C |
|
|
C++ |
|
|
Java |
|