Results 1 to 2 of 2
Thread: HTML Post
- 01-03-2011, 01:09 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
HTML Post
Hi I'm trying to make a program that will fill out a form (involving scroll downs) and click submit. For some reason I keep on getting an IO (file not found error). I think it might be because I'm writing the POST script wrong or I didn't add the click submit button to the script (If that is the issue, the submit button does not have a name field... How can I tell my script to click submit if it has no name field) Can someone please help me? Sorry if this is the wrong section to post this >.<
Java Code:import java.net.*; import java.io.*; public class Code { public static void main(String[] args) throws IOException { //Creates the URL where you enter the class try { URL webreg = new URL("http://soc.ess.rutgers.edu/soc"); } catch (MalformedURLException e) { //error if the above URL is not accessible // TODO Auto-generated catch block System.out.println("This program cannot access the class list website. Sucks to be you xP"); return; } //Writes the class you want to submit String content ="p_subj_cd=" + URLEncoder.encode("750", "UTF-8") + "&" + "p_course_no=" + URLEncoder.encode("204", "UTF-8") + "&" + "p_campus=" + URLEncoder.encode("NB", "UTF-8") + "&" + "p_yearterm=" + URLEncoder.encode("20111", "UTF-8"); //Tells the program that we are writing to the code given to us from the URL, webreg HttpURLConnection webregConnection =null; DataOutputStream output = null; //temporary for now try { webregConnection = (HttpURLConnection) (new URL("http://soc.ess.rutgers.edu/soc").openConnection()); //Specifies that we are gonna input something into this connection webregConnection.setDoInput(true); //Specifies that we are gonna use this connection for an output webregConnection.setDoOutput(true); /*possible error below for wrong content type * * sets the content type of the website */ webregConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); //States the PHP command Post webregConnection.setRequestMethod("POST"); //gets the output after submitting the class output = new DataOutputStream(webregConnection.getOutputStream()); output.writeBytes(content); output.flush(); output.close(); } catch (MalformedURLException e) { //error if internet connection is lost System.out.println("Sounds to me like you lost the internet while the program was running... TOO BAD T_T"); return; } catch (IOException e) { //I/O error e.printStackTrace(); System.out.println("Looks like Joe doesn't know how to program because you just ran into an I/O exception"); return; } //System.out.println(webregConnection.getInputStream()); //Prints the output BufferedReader bufferedReader = null; try { // Prepare a reader to read the response from the URLConnection // throws IOException bufferedReader = new BufferedReader(new InputStreamReader(webregConnection.getInputStream())); String responeLine; // Read untill there is nothing left in the stream // throws IOException while ((responeLine = bufferedReader.readLine()) != null) { System.out.println(responeLine); } } catch(IOException ioException) { System.out.println("Problems while reading the response"); ioException.printStackTrace(); // throw the exception so that the caller is aware that // there was some problems throw ioException; } finally { // Good practice: clean up the connections and streams // to free up any resources if possible if (bufferedReader != null) { try { // throws IOException bufferedReader.close(); } catch(Throwable ignore) { // Cannot do much with exceptions doing clean up // Ignoring all exceptions } } } } }
- 02-03-2011, 10:49 AM #2kevinpeter Guest
Here's a simple form that includes labels, radio buttons, and push buttons (reset the form or submit it):
<FORM action="http://somesite.com/prog/adduser" method="post">
<P>
<LABEL for="firstname">First name: </LABEL>
<INPUT type="text" id="firstname"><BR>
<LABEL for="lastname">Last name: </LABEL>
<INPUT type="text" id="lastname"><BR>
<LABEL for="email">email: </LABEL>
<INPUT type="text" id="email"><BR>
<INPUT type="radio" name="sex" value="Male"> Male<BR>
<INPUT type="radio" name="sex" value="Female"> Female<BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>
</FORM>
Similar Threads
-
POST information to html form via java?
By alacn in forum New To JavaReplies: 7Last Post: 08-20-2010, 06:01 AM -
where to post questions about javascript in html?
By iansane in forum Forum LobbyReplies: 2Last Post: 05-26-2010, 04:12 PM -
DOnt know if 1st post if did, I am VERY sorry for duplicate post. I have error messg
By afisher300 in forum New To JavaReplies: 3Last Post: 05-04-2009, 03:15 AM -
First post out of the way..
By sirwiggles in forum IntroductionsReplies: 0Last Post: 02-06-2009, 10:44 PM -
How can I include a html file in html textarea?
By surya_dks in forum New To JavaReplies: 2Last Post: 10-04-2008, 07:20 AM


LinkBack URL
About LinkBacks

Bookmarks