ASPX

短信验证码

Post.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Post.aspx.cs" Inherits="Post" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>云信互联DEMO</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table bordercolor="#dcdcdc" cellpadding="4" cellspacing="0" frame="box" rules="none"
style="border-collapse: collapse">
<tr>
<td background="#dcdcdc" class="frmHeader" style="border-right: white 2px solid">参数</td>
<td background="#dcdcdc" class="frmHeader">值</td>
</tr>
<tr>
<td class="frmText" style="font-weight: normal; color: #000000">account:</td>
<td><asp:TextBox CssClass="frmInput" Id="Txtaccount" runat="server" Width="272px" /></td>
</tr>
<tr>
<td class="frmText" style="font-weight: normal; color: #000000">password:</td>
<td><asp:TextBox CssClass="frmInput" id="Txtpassword" runat="server" Width="272px" /></td>
</tr>
<tr>
<td class="frmText" style="font-weight: normal; color: #000000">phone:</td>
<td>
<asp:TextBox CssClass="frmInput" id="Txtmobile" runat="server" name="scorpid" Width="272px" /></td>
</tr>
<tr>
<td class="frmText" style="font-weight: normal; color: #000000">msg:</td>
<td>
<asp:TextBox CssClass="frmInput" id="Txtcontent" runat="server" name="sprdid" Width="272px" /></td>
</tr>
<tr>
<td></td>
<td align="center"><asp:Button ID="ButSubmit" runat="server" Text="提交" OnClick="ButSubmit_Click" /></td>
</tr>
<tr>
<td></td>
<td align="center"><asp:Label ID="LabelRetMsg" runat="server"></asp:Label></td>
</tr>
</table>

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

Post.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

public partial class Post : System.Web.UI.Page
{
public static string PostUrl = ConfigurationManager.AppSettings["WebReference.Service.PostUrl"];
protected void Page_Load(object sender, EventArgs e)
{

}
protected void ButSubmit_Click(object sender, EventArgs e)
{

string un = this.Txtaccount.Text.Trim();
string pw = this.Txtpassword.Text.Trim();
string phone = Txtmobile.Text.Trim();

string content = System.Web.HttpUtility.UrlEncode("【云信互联】" + Txtcontent.Text.Trim(), Encoding.GetEncoding("GBK"));
string url = PostUrl;
string data= "method=sendSMS&extenno=&isLongSms=0&username=" + un + "&password=" + pw + "&smstype=0&mobile=" + phone + "&content=" + content;
//string result = doGetMethodToObj(url,data); //调用GET方式
string result = doPostMethodToObj(url, data); //调用POST方式
LabelRetMsg.Text = result;

}
//GET方式接口
public static string doGetMethodToObj(string url ,string data)
{
string geturl = url + "?" + data;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(geturl);
request.Method = "GET";
request.ContentType = "text/html;charset=utf-8";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("GBK"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}

//POST方式接口
public static string doPostMethodToObj(string url, string data) {

string result = String.Empty;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

httpWebRequest.ContentType = "application/x-www-form-urlencoded";

httpWebRequest.Method = "POST";

using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(data);
streamWriter.Flush();
streamWriter.Close();
HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream(), Encoding.GetEncoding("GBK")))
{
result = streamReader.ReadToEnd();
}
}
return result;
}

}

Web.Config

<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件以外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在
machine.config.comments 中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
WebReference.Service.PostUrl 短信发送接口
WebReference.Service.BalanceQueryUrl 获取余额接口
-->
<configuration>
<appSettings>
<add key="WebReference.Service.PostUrl" value="http://sms.smsyun.cc:9012/servlet/UserServiceAPI"/>
</appSettings>
<connectionStrings/>
<system.web>
<!--
设置 compilation debug="true" 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<compilation debug="true"/>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<!-- <authentication mode="Windows"/> -->
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>