DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

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

mediaguycouk

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 247
Hitting a website via C#.net command line
« on: July 06, 2009, 08: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
    • Participated in NANY Challenge Four Times
Re: Hitting a website via C#.net command line
« Reply #1 on: July 06, 2009, 09:39 AM »
2mediaguycouk
What do you mean by "hit a web address"?

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

Code: (csharp)
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;

namespace ConsoleApplication5
{
	class Program
	{
		static void Main( string[] args )
		{
			String url = @"http://www.google.com";
			String result = null;

			try
			{
				WebClient tmpClient = new WebClient();
				result = tmpClient.DownloadString(url);
				Console.Write(result);
			}
			catch (Exception exc)
			{
				Console.Write(exc.ToString());
			}
		}
	}
}

Little more info:
http://www.csharp411.com/read-a-web-page-in-c/
Надо было учиться, а не камни в школу бросать...
--
f0dder is my personal hero :)

mediaguycouk

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 247
Re: Hitting a website via C#.net command line
« Reply #2 on: July 06, 2009, 11: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
    • Participated in NANY Challenge Four Times
Re: Hitting a website via C#.net command line
« Reply #3 on: July 06, 2009, 12:01 PM »
2mediaguycouk
Maybe this will be nice addon for you:
http://www.codeproject.com/KB/cs/cron.aspx
Надо было учиться, а не камни в школу бросать...
--
f0dder is my personal hero :)

mediaguycouk

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 247
Re: Hitting a website via C#.net command line
« Reply #4 on: July 06, 2009, 01:17 PM »
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
    • Participated in NANY Challenge Four Times
Re: Hitting a website via C#.net command line
« Reply #5 on: July 06, 2009, 01:41 PM »
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/downloads/connector/net/6.0.html

With it you can simply connect to MySQL database (and change something, I assume) using something like:
http://bitdaddys.com/MySQL-ConnectorNet.html
Надо было учиться, а не камни в школу бросать...
--
f0dder is my personal hero :)

Original address: https://www.donationcoder.com/forum/index.php?topic=19074.0