Results 1 to 7 of 7
  1. #1
    Desh Banks is offline Member
    Join Date
    Nov 2010
    Posts
    12
    Rep Power
    0

    Default HttpConnection not using PHP script?

    I am making a connection to my server (hosted on my machine via an apache framework) from a java program using the following method:

    Java Code:
    try {
          URL ourURL = new URL("http://www.codingforums.com/external.php?type=RSS2"); //Coding Forums RSS Feed
          HttpURLConnection huc = (HttpURLConnection)ourURL.openConnection();            
          huc.setRequestMethod("GET");
          huc.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; JVM)");                        
          huc.setRequestProperty("Pragma", "no-cache");
          huc.connect();
                BufferedReader reader = new BufferedReader(new InputStreamReader(huc.getInputStream()));
    
          String line = null;
          while ((line = reader.readLine()) != null) {
              // Either do your parsing here, or append it to a StringBuffer for later use
          }
          catch(IOException ioe)
          {
              ioe.printStackTrace();
           }
          catch(Exception e)
          {
             System.err.println("General Exception " + e);
             e.printStackTrace();
           }
    (Example taken from Java connect to website - CodingForums.com).

    When I visit my webpage, it appears that a connection is made (in that no exceptions are thrown), but the php script running on my server does not seem to be executed. (It would incremement a counter in the SQL database, also hosted on my machine).

    Why does the php script not get executed?

    Thanks for any input.

  2. #2
    mi14chal is offline Member
    Join Date
    Dec 2010
    Posts
    15
    Rep Power
    0

    Default

    Java Code:
    while ((line = reader.readLine()) != null) {
              // Either do your parsing here, or append it to a StringBuffer for later use
          }
    Why didn't you do with response from server?

  3. #3
    Desh Banks is offline Member
    Join Date
    Nov 2010
    Posts
    12
    Rep Power
    0

    Default

    Thanks for the reply.

    Will reading stuff in cause execution of the PHP script? I thought the PHP script was executed on the server end as soon as the client connects to the server...

  4. #4
    mi14chal is offline Member
    Join Date
    Dec 2010
    Posts
    15
    Rep Power
    0

    Default

    Would you like to do?

  5. #5
    Desh Banks is offline Member
    Join Date
    Nov 2010
    Posts
    12
    Rep Power
    0

    Default

    My goal here is to get the php script on my site to execute. This happens whenever a person using a browser connects to my site. I want to reproduce this using a program to connect to my site instead of a browser.

  6. #6
    Desh Banks is offline Member
    Join Date
    Nov 2010
    Posts
    12
    Rep Power
    0

    Default

    It appears that what was needed was in fact to start reading from the page. Not sure why this has to happen, but it looks like it is getting the desired result. Thanks for the replies.

  7. #7
    Desh Banks is offline Member
    Join Date
    Nov 2010
    Posts
    12
    Rep Power
    0

    Default

    I do have a followup to this question - Does opening up tons of connections to different URL's really quickly look a lot like a DOS attack?

    I am writing a web crawler that visits each link it picks up on a given webpage, and continues to do this recursively. I don't want to risk my ISP or the given website thinking this is a DOS attempt.

    Thanks.

Similar Threads

  1. Script not working with IE7
    By sfphoto in forum New To Java
    Replies: 1
    Last Post: 12-13-2010, 06:08 PM
  2. Jquery pop out script
    By fOmey in forum New To Java
    Replies: 1
    Last Post: 12-03-2010, 03:13 AM
  3. Replies: 1
    Last Post: 05-25-2010, 10:53 AM
  4. HttpConnection problem
    By girija in forum Networking
    Replies: 2
    Last Post: 04-04-2008, 08:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •