JAVA – How To Post To A HTML/PHP Post Form

This example shows how to build up a string to post to a web form, and return the results generated.

Element1 is the first variable the the post accepts – “Value 1” is the literal string bieng passed to it.
Element2 is the second variable that the post accepts – “Value 2” is the literal string bieng passed to it.
Element3 is the third variable that the post accepts – “Value 2” is the literal string bieng passed to it.

http://www.examplewebsite.asp is the web page that the data is bieng posted to.

 

//Create Post String
String data = URLEncoder.encode(“Element1”, “UTF-8”) + “=” + URLEncoder.encode(“Value 1”, “UTF-8”);
data += “&” + URLEncoder.encode(“Element2”, “UTF-8”) + “=” + URLEncoder.encode(“Value 2”, “UTF-8”);
data += “&” + URLEncoder.encode(“Element3”, “UTF-8”) + “=” + URLEncoder.encode(“Value 3”, “UTF-8”);
                
         
// Send Data To Page
URL url = new URL(“http://www.examplewebsite.asp”);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
   
// Get The Response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
        System.out.println(line);
        //you Can Break The String Down Here
}

 

You can manipulate the line variable to read in the information returned from the post.

Advertisements

Find Model Number & Serial Number Of PC From Command Line

Here is a very simple script to return model and serial number information for your computer.

To retrieve serial number of the computer run the following command from command line

wmic bios get serialnumber

To retrieve model name of the computer run the following command from command line

wmic csproduct get name

This code doesn’t return information for all computers, but I’ve found it very usefull where its available.

Looking for an iPhone app? I can build it… get in touch 0844 833 0700 or rob@reactivapps.co.uk