Results 1 to 6 of 6
  1. #1
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Question URLConnection -- does it count as a "click"?

    Hello, i'm working on a program that will fetch a webpage from my company's site and download its content. I am having a hard time figuring out if URLConnection object used with the openConnection() method actually counts as a "hit" or "Click" or not? I would like it to count as this is an intranet site and it would be great to be able to monitor how many times employees have downloaded the page...

    this is the code i have so far.

    Java Code:
    	public static void httpConn(String destUrl, String searchTerm) throws IOException, InterruptedException {
    		strS = "";
    		try {
    			URL url = new URL(destUrl + searchTerm);
    			
    			Thread.sleep(500);
    			
                URLConnection conn =  url.openConnection();
                conn.setRequestProperty("User-Agent",
    									"Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.8.1.6) Gecko/20070723 BbeWeb/2.0.0.6 (Debian-2.0.0.6-0etch1)");
    			BufferedReader in = new BufferedReader(
    								new InputStreamReader(conn.getInputStream()));
    								
    			Thread.sleep(500);
    			System.out.println("Results returned... \n");
    			
    			while ((str = in.readLine()) != null) {
    				strS += "\n" + str;
    				//System.out.println(str);
    				str = "";
                }
                in.close();
            }
            catch (MalformedURLException e) {
    			System.err.println("Error: " + e.getMessage());
    		}
            catch (IOException e) {
    			System.err.println("Error: " + e.getMessage());
    		}
    		httpConnRun = true;
    	}
    thanks for any input.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: URLConnection -- does it count as a "click"?

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: URLConnection -- does it count as a "click"?

    Your server (the one with the page you are requesting via the URLConnection) does not really know where that connection is coming from, unless it is only counting certain browsers (unlikely), so any request should be registered.

    Besides, it's an intranet so you should be able to do a simple check.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: URLConnection -- does it count as a "click"?

    ok thanks. so just so i make sure i understand correctly... web servers in general cannot tell the difference between a web browser user mouse "click" on a link and a URLConnection fetching the data from the page, because they both accomplish the same thing - a GET request to the server to fetch the page requested, then the server returns that page as if a user clicked on it? I"m dont know a whole lot about how browsers work so please bear with me.

    Also, I dont have any feasible way to test on the intranet on our site as its hosted at another location and lots of internal traffic hits it (so i cant run my program, check the stats, run again, etc).

    thanks again, just trying to make sure i can rely on this method to accomplish the expected result. thanks!

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: URLConnection -- does it count as a "click"?

    Can you add a parameter to the URL the server could use to detect your testing?
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: URLConnection -- does it count as a "click"?

    that may be a good suggestion... 'll try it out. thanks norm.

Similar Threads

  1. Replies: 0
    Last Post: 06-07-2010, 06:23 PM
  2. output "left click"/enter command?
    By Arsenic in forum New To Java
    Replies: 2
    Last Post: 06-04-2009, 05:01 AM
  3. Replies: 2
    Last Post: 05-30-2009, 10:42 AM
  4. Count lines cointaining "word" in input file
    By gwithey in forum New To Java
    Replies: 5
    Last Post: 04-02-2009, 05:23 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 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
  •