如何发送对 URL 的响应?
我正在 MVC3 应用程序中研究 SMS 发送和接收功能。如何发送对 URL 的响应?任何访问我的页面的 URL 都应该得到“确定”或“已收到”之类的响应。
例如,请考虑下面的代码,该代码从提供商发送到我的网站。我需要将“ok”之类的响应文本或收到的响应文本发送到 stringResult。如果我可以用一些“成功”参数来响应 URL,那就太好了。
string stringResult = null;
stringpost ="parameters for url";
objWebRequest = (HttpWebRequest)WebRequest.Create("http://myip/app/action/receivesms?");
objWebRequest.Method = "POST"
if ((objProxy1 != null))
{
objWebRequest.Proxy = objProxy1;
}
objWebRequest.ContentType = "applicationwww-form-urlencoded";
objStreamWriter = new StreamWriter(objWebRequest.GetRequestStream());
objStreamWriter.Write(stringpost);
objStreamWriter.Flush();
objStreamWriter.Close();
objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();
objStreamReader = new StreamReader(objWebResponse.GetResponseStream());
stringResult = objStreamReader.ReadToEnd();
objStreamReader.Close();
return (stringResult);
I am working on SMS send and receive functionality in an MVC3 application. How can I send a response to a URL? Any URL that hits my page should get a response like "ok" or "received".
For example, consider the code below, which is sent from a provider to my site. I need to send a response text like "ok" or received to stringResult. If I can respond to URL with some "success" parameter that would be great.
string stringResult = null;
stringpost ="parameters for url";
objWebRequest = (HttpWebRequest)WebRequest.Create("http://myip/app/action/receivesms?");
objWebRequest.Method = "POST"
if ((objProxy1 != null))
{
objWebRequest.Proxy = objProxy1;
}
objWebRequest.ContentType = "applicationwww-form-urlencoded";
objStreamWriter = new StreamWriter(objWebRequest.GetRequestStream());
objStreamWriter.Write(stringpost);
objStreamWriter.Flush();
objStreamWriter.Close();
objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();
objStreamReader = new StreamReader(objWebResponse.GetResponseStream());
stringResult = objStreamReader.ReadToEnd();
objStreamReader.Close();
return (stringResult);
只需在控制器中执行此操作:
或者,如果您想使用 HTTP 代码而不是字符串,您可以执行以下操作:
Just do this in your controller:
Or, if you wanted to use HTTP codes instead of strings, you could do something like: