繁体   English   中英

从Windows客户端将参数传递到网页

[英]Pass parameters to web page from Windows client

我在MVC网站的控制器中具有以下方法:

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

    // Do stuff....
}

当我在地址栏中键入URL时,它工作正常,但是我需要从Windows客户端调用它。 如何在C#中执行此操作?

谢谢!

使用WebClient类从客户端发出HTTP请求。 如果您的客户端项目还没有引用,则需要添加对System.Web的引用。

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)
                )
            );
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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