问题描述
- c#腾讯企业邮箱二次开发实现新邮件提醒
-
新邮件提醒,需要维持长连接,图片是API文档关于长连接的描述,但是我获取到token,传入参数ver=0,返回错误,无效的请求,有做过这个功能的吗,求助啊!!
private bool GetPostData(string url, string pars, ref string json) { System.GC.Collect(); //url=请求的地址,pars= "var=0" string ret = ""; string postUrl = url; string paramData =pars; Encoding dataEncode = Encoding.UTF8; string token = this.GetToken(); HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl)); try { byte[] byteArray = dataEncode.GetBytes(paramData); //转化 //webReq.Timeout = 2 * 60 * 1000; webReq.KeepAlive = true; webReq.Host = "openapi.exmail.qq.com"; webReq.ProtocolVersion = HttpVersion.Version11; webReq.Method = "POST"; webReq.ContentType = "application/x-www-form-urlencoded"; webReq.Headers.Add("Authorization", "Bearer " + token); webReq.ContentLength = byteArray.Length; using (Stream newStream = webReq.GetRequestStream()) { newStream.Write(byteArray, 0, byteArray.Length);//写入参数 newStream.Close(); } using (HttpWebResponse response = (HttpWebResponse)webReq.GetResponse()) { using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { ret = sr.ReadToEnd(); } } } catch (Exception ex) { if (webReq != null) { webReq.Abort(); } //Log.Info("GetPostData:" + ex.Message + "," + url + "," + pars); json = ret; return false; } if (webReq != null) { webReq.Abort(); } json = ret; return true; }
解决方案
用写到链接里面的方法就可以成功了
解决方案二:
问题解决了吗,请问同步用户那里有没有报错,我同步用户也是报错,气死我了invalid_request。。麻烦给个回复谢谢了!
时间: 2024-12-25 07:14:17