太阳集团81068网址(中国)有限公司

太阳集团81068网址 > 帮助中心 > 代码示例 > C#

C# DEMO

asp.net调用示例向客户提供了asp.net调用HTTP接口的说明文档和调用示例,以尽可能减少客户开发的难度及工作量。


    using System;
    using System.Data;
    using System.Configuration;
    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.Text;
    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    //短信内容需进行GB2312编码
    Encoding content_encoding = Encoding.GetEncoding("GB2312");
    smswork dd = new smswork();
    string res = dd.smssend(TextBox1.Text.Trim(), TextBox2.Text.Trim(), TextBox3.Text.Trim(), TextBox4.Text.Trim());
    res=System.Web.HttpUtility.UrlDecode(res.Trim(), content_encoding);
    }
    }
    using System;
    using System.Data;
    using System.Configuration;
    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.Net;
    using System.Text;
    using System.IO;

        /// 
        /// smswork 的摘要说明
        ///
        
    public class smswork
    {
    string httpstr = "http://api.sms1086.com/api/";
    public smswork()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }

    //发送短信
    public string smssend(string username,string password,string mobiles,string content)
    {
    username = System.Web.HttpUtility.UrlEncode(username, Encoding.GetEncoding("GB2312"));
    content = System.Web.HttpUtility.UrlEncode(content, Encoding.GetEncoding("GB2312"));

    string sendurl = string.Format("{0}Send.aspx?username={1}&password={2}&mobiles={3}&content={4}"
    , httpstr
    ,username
    ,password
    ,mobiles
    ,content);

    return  HttpGet(sendurl);
    }


    private String HttpGet(String URL)
    {
    string Result = "";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
    //做请求
    request.ContentType = "text/HTML";
    request.MaximumAutomaticRedirections = 4;
    request.MaximumResponseHeadersLength = 4;
    request.Credentials = CredentialCache.DefaultCredentials;
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    //读结果
    Stream receiveStream = response.GetResponseStream();
    StreamReader readStream = new StreamReader(receiveStream, Encoding.GetEncoding("gb2312"));
    Result = readStream.ReadToEnd();
    response.Close();
    readStream.Dispose();

    return Result;
    }
    }

太阳集团81068网址|太阳集团81068网址

XML 地图 | Sitemap 地图