.net 钉钉发送企业消息返回 40035 不合法的参数
post的json字符串:"{\"touser\":\"1001|1002\",\"agentid\":\"5199109\",\"msgtype\":\"text\",\"text\":{\"content\":\"来至钉钉测试\"}}"
{"errcode":40035,"errmsg":"不合法的参数"}
以下两个方法都不行,都返回同样的错误。
但
通过 debug.dingtalk.com可以测试成功,json字符串和上面一样 {"touser":"1001|1002","agentid":"5199109","msgtype":"text","text":{"content":"来至钉钉测试"}}
方法内容:
一:
public static string SendRequest(string url, string body, Encoding encode)
{
WebClient wc = new WebClient();
//Encoding enc = Encoding.UTF8;
wc.Headers["Content-Type"] = "application/json; charset=utf-8";
return encode.GetString(wc.UploadData(new Uri(url), "POST", encode.GetBytes(body)));
}
二:
public string PostWebRequest(string postUrl, string paramData, Encoding dataEncode)
{
string ret = string.Empty;
try
{
byte[] byteArray = dataEncode.GetBytes(paramData); //转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/json; charset=utf-8";
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);//写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), dataEncode);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch (Exception ex)
{
return ex.Message;
}
return ret;
}
求救高人指点下。
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。