简体   繁体   中英

How to run a dynamic REST URL inside a loop in C# - Windows Form Application

How can i run a URL in c# I dont want to open the link on the browser...just run the url on background by the program.

Thanks

You can use HttpWebRequest and HttpWebResponse to make the call to a given URL and then parse the data accordingly. This can be spun off in a BackgroundWorker if so desired, as to not block the UI thread.

HttpWebRequest request = null;
for(int i = 0; i < count; i++)
{
    request = (HttpWebRequest)WebRequest.Create("http://www.mysite.com/orders?OrderNum=" + "i");
    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
        //ignore 
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM