我有两个asp.net应用程序运行在一个服务器上,一个是MVC-3,另一个不是.MVC应用程序有一个POST操作,它发送电子邮件并返回一个JSON对象。普通的asp.net应用程序能够以某种方式执行操作(从服务器)并接收JSON对象吗?我想它只是需要以某种方式执行一个帖子?
发布于 2014-01-21 01:27:26
找到答案:它是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();https://stackoverflow.com/questions/21177558
复制相似问题