C # send a text message,

Source: Internet
Author: User

C # send a text message,

 

Free third parties may be blocked due to the use of paid third parties.

Private const string Cdkey = "8 S **********************"; key id
Private const string Password = "151515 *******"; key Password
Private const string BaseUrl = "http: // hprpt ******* address *";
/// <Summary>
/// Send a timely text message
/// </Summary>
/// <Param name = "phone"> </param>
/// <Param name = "content"> </param>
/// <Returns> </returns>
Public string SendSms (string phone, string content)
{
// UTF-8
String Content = HttpUtility. UrlEncode (content. Trim (), System. Text. Encoding. GetEncoding ("UTF-8 "));
Phone = phone. Replace ("\ r \ n", ""). Trim ();
String sendurl = BaseUrl + "/sdkproxy/sendsms. action? Cdkey = "+ Cdkey +" & password = "+ Password +" & phone = "+ phone +" & message = "+ Content;
Var resultstr = string. Empty;
Try
{

Var rst = (HttpWebRequest) WebRequest. Create (sendurl); // main first step
Using (var stream = rst. GetResponse (). GetResponseStream () // Step 2
{
If (stream! = Null)
{
Using (var reader = new StreamReader (stream, Encoding. GetEncoding ("UTF-8") // 3
{
Resultstr = reader. ReadToEnd (); // 4

}
}
}
}
Catch (Exception ex)
{
Throw;
}
Return resultstr;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.