Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 10, 2016, 06:24:36 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Hitting a website via C#.net command line  (Read 3217 times)

mediaguycouk

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 245
    • View Profile
    • Mediaguy
    • Donate to Member
Hitting a website via C#.net command line
« on: July 06, 2009, 03:52:06 AM »
Easy one for you all I'm sure.

Is there a command that will hit a web address (for example mysite.com/scripts/update.php?id=1) but from a command line program?
Learning C# - Graham Robinson

fenixproductions

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,184
    • View Profile
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #1 on: July 06, 2009, 04:39:15 AM »
2mediaguycouk
What do you mean by "hit a web address"?

If you have getting webpage in mind then it is simple:

Code: C# [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. using System.Net;
  6.  
  7. namespace ConsoleApplication5
  8. {
  9.         class Program
  10.         {
  11.                 static void Main( string[] args )
  12.                 {
  13.                         String url = @"http://www.google.com";
  14.                         String result = null;
  15.  
  16.                         try
  17.                         {
  18.                                 WebClient tmpClient = new WebClient();
  19.                                 result = tmpClient.DownloadString(url);
  20.                                 Console.Write(result);
  21.                         }
  22.                         catch (Exception exc)
  23.                         {
  24.                                 Console.Write(exc.ToString());
  25.                         }
  26.                 }
  27.         }
  28. }

Little more info:
http://www.csharp411...ead-a-web-page-in-c/

mediaguycouk

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 245
    • View Profile
    • Mediaguy
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #2 on: July 06, 2009, 06:13:54 AM »
When I say hit I mean like a Cron job makes a web page do a task. The webserver has to process the page but the C# program doesn't need to read anything (except maybe to realise that the page has been hit and not a 404).

[Edit]
Just to clarify, I think your code will be fine for that. Probably better than fine as I can output something like 'Success' and then check that the word success has been passed back.
Learning C# - Graham Robinson

fenixproductions

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,184
    • View Profile
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #3 on: July 06, 2009, 07:01:43 AM »
2mediaguycouk
Maybe this will be nice addon for you:
http://www.codeproje....com/KB/cs/cron.aspx

mediaguycouk

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 245
    • View Profile
    • Mediaguy
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #4 on: July 06, 2009, 08:17:50 AM »
I'll bookmark that but not what I'm looking for this time.

My code is does the following

- Encode news
- Upload to Flash Streaming server
- Overwrite last news
- Change date by making site.com/admin/updatedate?news=bbcmonday&newdate=090609

The program can move the file, but it cannot write to the mysql database, so I have to make the website do it but only once the program is finished encoding.

Many thanks. Will be using the code from your first link

Learning C# - Graham Robinson

fenixproductions

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,184
    • View Profile
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #5 on: July 06, 2009, 08:41:51 AM »
The program can move the file, but it cannot write to the mysql database, so I have to make the website do it but only once the program is finished encoding.

Maybe Connector/Net will solve your problems:
http://dev.mysql.com...nnector/net/6.0.html

With it you can simply connect to MySQL database (and change something, I assume) using something like:
http://bitdaddys.com...QL-ConnectorNet.html