C# DEMO
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace sendDemo
{
classProgram
{
staticvoid Main(string[] args)
{
//请求地址请登录zz.253.com获取
String account ="N9994784";//API账号
String password ="Dasibugaosuni12";//API密码
String url ="[[[
http://smssh1.253.com/msg/send/json";//API接口地址](http://smssh1.253.com/msg/send/json";//API接口地址](http://smssh1.253.com/msg/send/json";//API接口地址](http://smssh1.253.com/msg/send/json";//API接口地址)](http://smssh1.253.com/msg/send/json";//API接口地址](http://smssh1.253.com/msg/send/json";//API接口地址](http://smssh1.253.com/msg/send/json";//API接口地址](http://smssh1.253.com/msg/send/json";//API接口地址))\
)
String phone ="18516627499";
String msg ="【253云通讯】您的验证码是123456";//253短信测试内容
string postJsonTpl ="\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
string jsonBody =string.Format(postJsonTpl, account, password, phone, msg);
String result= doPostMethodToObj(url,"{" + jsonBody +"}");
}
publicstaticstring doPostMethodToObj(string url,string jsonBody)
{
string result =String.Empty;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType ="application/json";
httpWebRequest.Method ="POST";
// Create NetworkCredential Object
NetworkCredential admin_auth =newNetworkCredential("username","password");
// Set your HTTP credentials in your request header
httpWebRequest.Credentials = admin\_auth;
// callback for handling server certificates
ServicePointManager.ServerCertificateValidationCallback =delegate {returntrue; };
using (StreamWriter streamWriter =newStreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write\(jsonBody\);
streamWriter.Flush\(\);
streamWriter.Close\(\);
HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (StreamReader streamReader =newStreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd\(\);
}
}
return result;
}
}
修改于 2021-11-25 05:41:38