【问题标题】:can a MVC 3 app execute an Action in a different app on the same serverMVC 3 应用程序可以在同一服务器上的不同应用程序中执行操作吗
【发布时间】:2014-01-17 03:56:05
【问题描述】:

我在一台服务器上运行了两个 asp.net 应用程序,一个是 MVC-3,另一个不是。 MVC 应用程序有一个 POST 操作,它发送一封电子邮件并返回一个 JSON 对象。普通的 asp.net 应用程序能否以某种方式执行操作(来自服务器)并接收 JSON 对象?我猜它只需要以某种方式执行 POST 吗?

【问题讨论】:

    标签: asp.net asp.net-mvc-3


    【解决方案1】:

    找到答案:就是HttpWebRequest方法,使用如下。

    string data = "data to post";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("put URL here"); 
    // set post headers
    request.Method = "POST";
    request.KeepAlive = true;
    request.ContentLength = data.Length;
    request.ContentType = "application/x-www-form-urlencoded";
    System.IO.StreamWriter writer = new System.IO.StreamWriter(request.GetRequestStream());
    writer.Write(data);
    writer.Close();
    writer.Dispose();
    // next line posts the data to the URL
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    

    【讨论】:

    • 感谢@erict 发布答案。我相信这也正是我所需要的。
    猜你喜欢
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 2018-06-08
    相关资源
    最近更新 更多