服务端代码:
string Url = “https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=”+ token;
var postdata = new
{
touser = openId,
template_id = templeteId,
page = “index”,
data = new
{
thing1 = new
{
value = “今日行程”
},
date2 = new
{
value = “2020-03-01”
},
thing4 = new
{
value = “请做好准备,即将出发”
}
}
};
wenXinResult = HttpHelper.HttpPostJson(Url, JsonHelper.Serialize(postdata));
httppost代码:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = “POST”;
req.ContentType = “application/json”;
Stream myRequestStream = req.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding(“gb2312”));
myStreamWriter.Write(postDataStr);
myStreamWriter.Close();
HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
if (string.IsNullOrWhiteSpace(rsp.CharacterSet))
{
return GetResponseAsString(rsp, Encoding.UTF8);
}
else
{
Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);
return GetResponseAsString(rsp, encoding);
}
请大神帮我看下那里有问题,感谢!