Urgent! I need help on a Java project for school! Can you fix this code?
-
I am working on a project for my AP Java (Computer Science A) class and I need your help! I am trying to post data to a html form from a particular website: http://www.upcdatabase.com/itemform.asp The Java code I wrote kind of sort of works, but returns the website source code that doesn't contain the results of the query! If I manually type in the following UPC code to the form: 075992584425 It will return: Description: Madonna - Like A Prayer Size/Weight: CD ... and a bunch of other corresponding data. The Java Class code that I wrote for this: // BEGIN CODE HERE ----------------------------------------… import java.net.*; import java.io.*; public class ReadWriteURL { public void PostToForm() { try { //Create Post String String data = URLEncoder.encode("075992584425", "UTF-8"); System.out.println("data= " + data); System.out.println(); // Send Data To Page URL url = new URL("http://www.upcdatabase.com/itemform… 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 } } catch (Exception e) { System.out.println(" There was an error"); } } } // END CODE ----------------------------------------… Can you quickly fix this code so that it retrieves the correct data, for the search value? (Same data like entering by hand) I cannot figure out from the source code of the HTML page what to send or how to find out what the exact URL is to send it to.
-
Answer:
That itemform.asp page uses JavaScript to catch the form submission and construct an URL that refers to the data for the UPC code you entered into the form. That URL is "http://www.upcdatabase.com/item/" followed by the UPC code. So, for instance, the URL for your example would be "http://www.upcdatabase.com/item/0759925… You should see that URL in your browser's address bar when the answer page is shown. If you make your URLConnection to that URL instead of to the itemform.asp page then you don't need to worry about the form and you don't need to send any input into the connection. You should be able to simply read the result.
Sylvie at Yahoo! Answers Visit the source
Related Q & A:
- I need help with a song I heard.Best solution by Yahoo! Answers
- I need help with a Romeo and Juliet essay.Best solution by Yahoo! Answers
- I need help choosing a camera.Best solution by Yahoo! Answers
- I need help simplifying a rational expression.Best solution by purplemath.com
- I need help finding a photographer.Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.