#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    0
    Rep Power
    0

    Question sending out a get request to another page


    I want to do some real distributed computing.

    lets say i want to get a book price from barnesandnoble.com, i know that by going to http://shop.barnesandnoble.com/bookS...sbn=0062514792 i can get information on the book referred to by isbn=0062514792 such as the listed price.

    now using AOLserver and the Tcl API, i can use the ns_httpget procedure which grabs info off a foreign server such as:

    ns_httpget "http://www.census.gov/cgi-bin/popclock"

    however I am using JSP and would like to get the same effect.

    If anyone has any ideas for acheving this goal please enlighten me.

    thanks,
    -phil
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    0
    Rep Power
    0
    in case anyone cares.....
    i found a way to do it in Java
    the following is some sample code:
    <%
    // if i want to get the present price of a book with isbn number
    //0062514792 from barnesandnoble.com i would do the collowing
    //in my JSP page

    String url = "http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=0062514792";

    URL u = null;
    HttpURLConnection urlc = null;

    // Open a connection to a specified URL
    try {
    u = new URL (url);
    }
    catch (MalformedURLException mfurle) {
    System.err.println ("URL: " + url + "\t\tMalformed URL " + mfurle.getMessage());
    }
    catch (Exception e) {
    System.err.println ("URL: " + url + "\t\tException: " + e.getMessage());
    }


    // create HttpURLConnection object and then connect to the page
    try {
    urlc = (HttpURLConnection)u.openConnection ();
    }
    catch (UnknownHostException uhe) {
    System.err.println (url + "\tUnknown Host " + uhe.getMessage());
    }
    catch (NoRouteToHostException nrthe) {
    System.err.println (url + "\tNo Route to Host " + nrthe.getMessage());
    }
    catch (Exception e) {
    System.err.println (url + "\tException " + e.getMessage());
    }

    // Define some HTTP header information about yourself
    urlc.setRequestProperty ("User-Agent:", "just-a-test-v1.0");
    urlc.setRequestProperty ("From:", "me@myaddress.edu");

    // Now we can connect and start loading the page
    try {
    urlc.connect ();
    }
    catch (IOException ioe) {
    System.err.println ("Connection Failure " + url + "\tException: " + ioe.getMessage());
    }

    // Load page contents using a buffered reader and the URLConnection.getInputStream()
    // method. You should use this technique for first loading the robots.txt file for
    // the site. If it exists, pay attention to it!
    String line;
    BufferedReader br = new BufferedReader (new InputStreamReader (urlc.getInputStream ()));
    while ( (line = br.readLine ()) != null ) {
    if (line.trim().startsWith("Our Price:")){
    out.write("TRUE\n");
    out.write(line+"\n");
    }
    }

    // Close the stream when you're done, and then disconnect
    br.close ();
    urlc.disconnect ();

    %>

IMN logo majestic logo threadwatch logo seochat tools logo