代码示例

代码下载C#代码示例 在线技术支持

	void SendSms(String accName,String accPwd,String aimcodes,String content)
	{
	    string formUrl = "http://www.lx598.com/sdk/send";//url地址
	    string ReStr;
        //参数
        string formData="" ;
        DateTime Date= DateTime.Now;

        formData = formData +  "&accName=" +accName.Trim() + 
        	"&accPwd=" + md5(accPwd.Trim())+
        	"&content=" +content.Trim() + 
        	"&aimcodes=" +aimcodes.Trim(); 

        CookieContainer cookieContainer = new CookieContainer();
        // 将提交的字符串数据转换成字节数组
        //byte[] postData = Encoding.UTF8.GetBytes(formData);
        Encoding myc= Encoding.GetEncoding("UTF-8");
        byte[] postData =myc.GetBytes(formData);
        // 设置提交的相关参数
        HttpWebRequest request = WebRequest.Create(formUrl) as HttpWebRequest;
        Encoding myEncoding = Encoding.GetEncoding("UTF-8");
        request.Method = "POST";
        request.KeepAlive = false;
        request.AllowAutoRedirect = true;
        request.ContentType = "application/x-www-form-urlencoded";
        request.CookieContainer = cookieContainer;
        request.ContentLength = postData.Length;

        // 提交请求数据
        System.IO.Stream outputStream = request.GetRequestStream();
        outputStream.Write(postData, 0, postData.Length);
        outputStream.Close();

        HttpWebResponse response;
        Stream responseStream;
        StreamReader reader;
        string srcString;
        response = request.GetResponse() as HttpWebResponse;
        responseStream = response.GetResponseStream();
        reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
        ReStr = reader.ReadToEnd(); //返回值
        Console.WriteLine( "错误信息:" + ReStr);
        reader.Close();		
	}