0

I have the following method in a controller in an MVC website:

[WebGet]
public void SaveInfo()
{
    string make = Request.QueryString["Make"];
    string model = Request.QueryString["Model"];

    // Do stuff....
}

It works fine when I type the URL in the address bar, but what I need to do is call this from a Windows client. How do I do this in C#?

Thanks!

user390480
  • 1,655
  • 4
  • 28
  • 61

1 Answers1

0

Use the WebClient class to make an HTTP request from the client. You'll need to add a reference to System.Web if your client project doesn't already have one.

using System.Net;
using System.Web;

    static void SaveInfo(string make, string model)
    {
        using (WebClient webClient = new WebClient())
        {
            string response = webClient.DownloadString(
                String.Format(
                    "http://yoursite/ControllerName/SaveInfo?make={0}&model={1}",
                    HttpUtility.UrlEncode(make),
                    HttpUtility.UrlEncode(model)
                )
            );
        }
    }
Ross McNab
  • 11,337
  • 3
  • 36
  • 34