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);
Just do this in your controller:
public ActionResult YourAction()
{
return Content("OK");
}
Or, if you wanted to use HTTP codes instead of strings, you could do something like:
public ActionResult YourAction()
{
// 204 is the HTTP code for OK with no content
return new HttpStatusCodeResult(204);
}
stringResult = objStreamReader.ReadToEnd(); stringResult in your code recieve server response. this response contains ok or succuessfully sent. you have to interpret the response and then send your message to the client and you can call this send smsmethod using ajax. In ajax method call you can show dialog of "OK" or "RECIEVED"
精彩评论