topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Wednesday December 11, 2024, 8:33 pm
  • Proudly celebrating 15+ 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 6125 times)

mediaguycouk

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 247
    • View Profile
    • Mediaguy
    • Donate to Member
Hitting a website via C#.net command line
« on: July 06, 2009, 03:52 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,186
    • View Profile
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #1 on: July 06, 2009, 04:39 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: 247
    • View Profile
    • Mediaguy
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #2 on: July 06, 2009, 06:13 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,186
    • View Profile
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #3 on: July 06, 2009, 07:01 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: 247
    • View Profile
    • Mediaguy
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #4 on: July 06, 2009, 08:17 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,186
    • View Profile
    • Donate to Member
Re: Hitting a website via C#.net command line
« Reply #5 on: July 06, 2009, 08:41 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.
-mediaguycouk (July 06, 2009, 08:17 AM)

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