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;
}