Link to home
Start Free TrialLog in
Avatar of pdering
pdering

asked on

How to post url in C#

I need to "post" a web url in the background and repeat it every 60 seconds.  Would prefer not to use the Windows Scheduler.  

For example....
http://www.domain.com/index.php?userkeepalive=user1

I don't need to view the page - just hit the url.  (Kind of like curl).  How would   I do this in C#?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would do it in a different way and not let the thread sleep for a minute every time. You can use a Timer control to do work on a timed interval.

public class Example {
    private Timer timer;
    private WebClient client;

    public Example() {
        this.client = new WebClient();
        this.timer = new Timer();
        this.timer.Interval = 60000;
        this.timer.Tick += new EventHandler<EventArgs>(timer_Tick);
        this.timer.Enabled = true;
    }

    private void timer_Tick(object sender, EventArgs e) {
        this.client.DownloadString("http://www.example.com");
    }
}

Open in new window


Also, the WebClient's DownloadString requests (HTTP GET) a URL whereas the UploadString performs a HTTP POST.
Avatar of pdering
pdering

ASKER

What is the difference between UploadString and DownloadString?
@CodeMasterAlex
I would do it in a different way and not let the thread sleep for a minute every time. You can use a Timer control to do work on a timed interval.
If it's a Console application, does it really matter?

@pdering
What is the difference between UploadString and DownloadString?
As CodeMasterAlex indicated, you would use UploadString to perform a POST.
@kaufmed:

I don't know what kind of application it is. I don't think it would really matter, it is more a matter of preference. Reading the remarks at http://msdn.microsoft.com/en-us/library/system.timers.timer%28v=vs.100%29.aspx suggests it is a better option in this case.