可以在MVC 3应用程序在不同的应用程序运行在同一台服务器上的操作 [英] can a MVC 3 app execute an Action in a different app on the same server

查看:83
本文介绍了可以在MVC 3应用程序在不同的应用程序运行在同一台服务器上的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have two asp.net applications running on one server, one is MVC-3, the other is not. the MVC application has a POST action which sends an email and returns a JSON object. Can the plain asp.net application somehow execute the action (from server) and receive the JSON object? I guess it just needs to execute a POST somehow?

推荐答案

找到了答案:这是HttpWebRequest的方法,使用如下

Found the answer: It is the method HttpWebRequest, used as follows.

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

这篇关于可以在MVC 3应用程序在不同的应用程序运行在同一台服务器上的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆