如何在asp.net mvc中使用http api发送短信

时间:2017-12-09 15:24:31

标签: c# asp.net asp.net-mvc sms-gateway

我想使用HTTP SMS API从我的asp.net mvc应用程序发送短信,我从clickatell获得了http sms api。我试图将它集成到我的asp.net mvc应用程序中,但是我收到一条错误消息:“底层连接已关闭:发送时发生意外错误”你能提供有效的代码吗?这是我的行动方法:

        // GET: Members/SendSMS
        public ActionResult SendSMS()`enter code here`
        {
        return View();
        }





        [HttpPost]

        public ActionResult SendSMS(object sender, EventArgs e, Member     

        member)
        {
        string message = member.Message;
        string cell = member.Cell;

        // use the API URL here  
        string strUrl = "https://platform.clickatell.com/messages     

       /http/send?apiKey=xxxxxxx&to=xxxxxxx&   

        content=xxxxxxxx";
        // Create a request object  
        WebRequest request = HttpWebRequest.Create(strUrl);
        // Get the response back  
        HttpWebResponse response =   

        (HttpWebResponse)request.GetResponse();
        Stream s = (Stream)response.GetResponseStream();
        StreamReader readStream = new StreamReader(s);
        string dataString = readStream.ReadToEnd();
        response.Close();
        s.Close();
        readStream.Close();

        return View("Answer", member);
    } 

这是我的SendSms视图:

    @model WebApplicationSMS.Models.Member

    @{
    ViewBag.Title = "SendSMS";
    }

   <h2>SendSMS</h2>




  <!DOCTYPE html>
  <html>
  <head>
  <meta name="viewport" content="width=device-width" />

  </head>
  <body>
   <div>
    <br /><br />

    <br />
    @using (Html.BeginForm())
    {  @Html.ValidationSummary()
        <p> Cell Number: @Html.TextBoxFor(x => x.Cell, new { @class =   
    "form-control" }) </p>
        <p>Message: @Html.TextAreaFor(x => x.Message, new { @class =   

    "form-control", rows = '5' }) </p>

        <input type="submit" value="Submit " />
    }


     </div>
   </body>
   </html> 


   @section Scripts {
   @Scripts.Render("~/bundles/jqueryval")
   }

任何可以提供协助的人?我将非常感谢您的协助。

0 个答案:

没有答案