您在这里:文档首页 - 源码示例

C#

  
 using System;    
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;    
     
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 = this.Txtmobile.Text.Trim();    
        string content = "【麦讯通】"+this.Txtcontent.Text.Trim();    
     
        string postStrTpl="account={0}&pswd={1}&mobile={2}&msg={3}&needstatus =true";    
     
               UTF8Encoding encoding = new UTF8Encoding();    
               byte[] postData = encoding.GetBytes(string.Format(postStrTpl, un, pw, phone, content));    
               System.GC.Collect();    
               HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(PostUrl);    
               myRequest.KeepAlive = false;    
               myRequest.Method = "POST";    
               myRequest.ContentType = "application/x-www-form-urlencoded";    
               myRequest.ContentLength = postData.Length;    
               myRequest.Timeout = 5000;    
               Stream newStream = myRequest.GetRequestStream();    
               // Send the data.    
               newStream.Write(postData, 0, postData.Length);    
               newStream.Flush();    
               newStream.Close();    
     
               HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();    
     
               if (myResponse.StatusCode == HttpStatusCode.OK)    
               {    
                   //StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);    
                   //LabelRetMsg.Text = reader.ReadToEnd();    
                   myResponse.Close();    
                   myRequest.Abort();    
                   Log.WriteTextLog("短信发送成功:" + phone + "," + content);    
                   return 1;    
               }    
               else    
               {    
                   myRequest.Abort();    
                   myResponse.Close();    
                   Log.WriteTextLog("短信发送失败 " + phone + "," + content);    
                   //访问失败    
                   return 0;    
               }    
    }    
}   
                   <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Post.aspx.cs" Inherits="Post" %>  
                     
                     
                   
联系我们
即刻申请免费测试账号
联系我们
COPYRIGHT @ 2017-2020 深圳市麦讯通科技有限公司 ALL RIGHTS RESERVED.
粤公网安备 44030702001630号
技术支持:百川网络