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;
        }

3个回答

用写到链接里面的方法就可以成功了

问题解决了吗,请问同步用户那里有没有报错,我同步用户也是报错,气死我了invalid_request。。麻烦给个回复谢谢了!

Content-Type=application/json
Ver=1386593148546
access_token=xx,保证access_token有效就可以了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐