发送短信(string转换为JSON)
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo1113
{
public sealed class Program
{
public static void Main()
{
SmsMessage smsMessage = new SmsMessage();
smsMessage.OpenId = "123";
smsMessage.TempleaseId = "abc";
smsMessage.MessageInfo = new List<MessageInfo> { new MessageInfo{
Key="1",Value="q"
},new MessageInfo{Key="2",Value="w"}};
//Newtonsoft.Json
string json = JsonConvert.SerializeObject(smsMessage);
SmsMessageDictionary smsMessageDictionary = new Program.SmsMessageDictionary();
smsMessageDictionary.OpenId = "123";
smsMessageDictionary.TempleaseId = "abc";
Dictionary<string, string> list = new Dictionary<string, string>();
list.Add("d", "1");
list.Add("d1", "13");
list.Add("d2", "14");
smsMessageDictionary.MessageInfo = list;
Console.WriteLine("Json=" + json);
Console.WriteLine("Json2=" + JsonConvert.SerializeObject(smsMessageDictionary));
Console.ReadKey();
string sJson = JsonConvert.SerializeObject(smsMessage); //传入参数有误时,可能会出现"远程服务器返回错误: (500) 内部服务器错误。"的错误
System.Text.UTF8Encoding encodeing = new UTF8Encoding();
byte[] contentBytes = encodeing.GetBytes(sJson);
try
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://。。。。。。。。。"));
//增加下面两个属性即可 (防止出现“基础连接已经关闭: 接收时发生错误。”的错误)
webRequest.KeepAlive = false;
webRequest.ProtocolVersion = HttpVersion.Version10;
//webRequest.Proxy = new WebProxy("url", 80);
//webRequest.UserAgent = "Mozilla-Firefox-Spider(Wenanry)";
webRequest.Method = "POST";
//webRequest.ContentType = "application/json";
webRequest.ContentType = "application/json";
webRequest.Accept = "application/json";
webRequest.ContentLength = sJson.Length; //这边是JSON的长度
using (Stream newStream = webRequest.GetRequestStream())
{
newStream.Write(contentBytes, 0, contentBytes.Length); //这边读取的是字节
}
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
//HttpWebResponse res;
//try
//{
// res = (HttpWebResponse)webRequest.GetResponse();
//}
//catch (WebException ex)
//{
// res = (HttpWebResponse)ex.Response;
//}
using (var response = (HttpWebResponse)webRequest.GetResponse())
{
var stream = response.GetResponseStream();
using (var sr = new StreamReader(stream, Encoding.Default))
{
str = sr.ReadToEnd();
}
stream.Dispose();
}
// JObject jo = JObject.Parse(str);
// string err = jo["errCode"].ToString();
JObject jopdd = JObject.Parse(str);
string err = jopdd["errorCode"].ToString();
string errMsg = jopdd["errorMessage"].ToString();
}
catch (Exception e)
{
string aa = "aaa";
}
}
public class SmsMessageDictionary
{
public string OpenId { get; set; }
public string TempleaseId { get; set; }
public Dictionary<string, string> MessageInfo { get; set; }
}
public class SmsMessage
{
public string OpenId { get; set; }
public string TempleaseId { get; set; }
public List<MessageInfo> MessageInfo { get; set; }
}
public class MessageInfo
{
public string Key { get; set; }
public string Value { get; set; }
}
}
}
发送短信(string转换为JSON)的更多相关文章
- java + maven 实现发送短信验证码功能
如何使用java + maven的项目环境发送短信验证码,本文使用的是榛子云短信 的接口. 1. 安装sdk 下载地址: http://smsow.zhenzikj.com/doc/sdk.html ...
- java发送短信验证码
业务: 手机端点击发送验证码,请求发送到java服务器端,由java调用第三方平台(我们使用的是榛子云短信http://smsow.zhenzikj.com)的短信接口,生成验证码并发送. SDK下载 ...
- android发送短信验证码并自动获取验证码填充文本框
android注册发送短信验证码并自动获取短信,截取数字验证码填充文本框. 一.接入短信平台 首先需要选择短信平台接入,这里使用的是榛子云短信平台(http://smsow.zhenzikj.com) ...
- java攻城师之路(Android篇)--搭建开发环境、拨打电话、发送短信、布局例子
一.搭建开发环境 1.所需资源 JDK6以上 Eclipse3.6以上 SDK17, 2.3.3 ADT17 2.安装注意事项 不要使用中文路径 如果模拟器默认路径包含中文, 可以设置android_ ...
- Android 打开URL中的网页和拨打电话、发送短信功能
拨打电话需要的权限 <uses-permission android:name="android.permission.CALL_PHONE"/> 为了省事界面都写一起 ...
- 移动MAS短信平台发送短信
MAS短信平台发送短信分为两种方式 参考文档下载 一.sdk调用 using mas.ecloud.sdkclient; using System; namespace 短信发送 { class Pr ...
- android: 接收和发送短信
8.2 接收和发送短信 收发短信应该是每个手机最基本的功能之一了,即使是许多年前的老手机也都会具备这 项功能,而 Android 作为出色的智能手机操作系统,自然也少不了在这方面的支持.每个 A ...
- 阿里大鱼.net core 发送短信
阿里大鱼还未提供 .net core 版SDK,但提供了相关API,下面是.net core版实现,只是简单发送短信功能: using System; using System.Collections ...
- 短信接口调用以及ajax发送短信接口实现以及前端样式
我们短信api用的是云信使平台提供的非免费短信服务:官网提供的demo有两种,分别是function加其调用.class文件加其调用. 在这里我们用class文件加调用: 首先,ThinkPHP里面自 ...
- 如何使用微信小程序云函数发送短信验证码
其实微信小程序前端和云端都是可以调用短信平台接口发送短信的,使用云端云函数的好处是无需配置域名,也没有个数限制. 本文使用的是榛子云短信平台(http://smsow.zhenzikj.com) ,S ...
随机推荐
- Networkcommd V3 新功能之一 拒绝服务攻击防护 ( DOSProtection)
NetworkComms网络通信框架序言 DOSProtection类能够防御拒绝服务攻击 启用方法: NetworkComms.DOSProtection.Enabled = true; 相关资料:
- numtoyminterval函数——数字转换函数
numtoyminterval函数——数字转换函数 ----转至51CTO 水滴的博客 语法:NUMTOYMINTERVAL ( n , 'char_expr' ) c ...
- code of C/C++ (1)
去年,王老师拷贝给我一些代码,非常感激,老爷子的水平我这个小辈只能仰视,代码都是来自他所教的课程,有些课程因为这几年据说太难都给取消掉了,实在是 我们学校的损失. C/C++代码都是在讲述一些非常基本 ...
- Jquery之ShowLoading遮罩组件
From:http://www.cnblogs.com/eczhou/archive/2012/12/18/2822788.html 一.遮罩用途及效果 ShowLoading这个jQuery插件设计 ...
- jquery 、 JS 脚本参数的认识与使用
jquery . JS 脚本参数的认识与使用 如何使用jquery刷新当前页面 下面介绍全页面刷新方法:有时候可能会用到 window.location.reload(); //刷新当前页面. par ...
- vs2013 遇到的web性能记录器无法使用问题
诊断和修复Web测试记录栏的问题.自2005年以来VSTS运也出现了各种由客户多年来提出不同的问题.记录Web测试时,这在一定程度经常提到的一个话题是一个残疾或不存在的Web测试记录吧.因为它可以令人 ...
- qpython3 读取安卓lastpass Cookies
之前我的博客写了python读取windows chrome Cookies,沿着同样的思路,这次本来想尝试读取安卓chrome Cookies, 但是可能是chrome的sqlite3版本比较高读取 ...
- ajax对象属性withCredentials
默认情况下,ajax跨源请求不提供凭据(cookie.HTTP认证及客户端SSL证明等).通过将设置ajax的withCredentials属性设置为true,可以指定某个请求应该发送凭据.如果服务器 ...
- CSS 第四天 多重背景 变形 过渡
背景原点:background-origin 图片起始位置 border-box包括边框 padding-box边框内 content-box 内容内 **background-repeat 为no- ...
- hdu 2067
ps:晕,for()是先判断,再执行的...WA了一次...这个也是递推.第一列只有从上面来的点,所以全部是1(dp[i][0]=1) 其他的可以从上面或者左边来所以是 dp[i][j]=dp[i-1 ...