Simple example:
Imports java.io.inputstream; import java.io.outputstream; import java.net.URL; import java.net.urlencoder; import java.net.httpurlConnection;
Public class test {public static void main (string [] args) throws exception {
URL http_url = new URL (http: //localhost/smgp/submit.jsp); // define a URL object, ready to connect to http: //localhost/smgp/submit.jsp HttpURLConnection http_conn = (HttpURLConnection) http_url.openConnection () ;
http_conn.setdooutput (true); http_conn.setRequestMethod ("post"); // Transfer POST mode
OutputStream OS = http_conn.getOutputStream ();
// To read binary data from the input stream, the G E T I N P U T S T R E A M () method is obtained, and the I n p U T S T R e A m is returned. Our transmission parameters are transmitted in 2-based values.
StringBuffer str_buf = new stringbuffer (4096);
// Use the StringBuffer Transfer Parameters, the following param_1 is the received parameter name of the web page we have to access, and param_1_value This is the value passed accordingly. Str_buf.append (param_1) .Append ("="). Append (param_1_value) .append ("&"); str_buf.append (param_2) .append ("="). append (param_2_value) .append ("&" ); Str_buf.append (param_3) .append ("="). Append (param_3_value) .Append ("&"); os.write (Str_buf.tostring (). GetBytes ()); // Transfer to binary data OutputStream Transfer. To this step, you will successfully pass the parameters to the web page. System.out.println (" POST URL: OK !!! "); http_conn.disconnect (); // Disconnected
}
}