生成小程序码 (errcode: 41030) invalid page hint“Stream.Length”引发了“System.NotSupportedException”类型的异常

   public string GetQrcode(string strToken, string content)
        {
            string strResult = "";
            string url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + strToken;
            System.Net.WebRequest wRequest = System.Net.WebRequest.Create(url);
            wRequest.Method = "post";
            wRequest.ContentType = "application/x-www-form-urlencoded";
            #region 添加Post 参数
            byte[] data = Encoding.UTF8.GetBytes(content);
            wRequest.ContentLength = data.Length;
            using (Stream reqStream = wRequest.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);
                reqStream.Close();
            }
            #endregion

            HttpWebResponse resp = (HttpWebResponse)wRequest.GetResponse();
            Stream stream = resp.GetResponseStream();
            ////获取响应内容
            //using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            //{
            //    strResult = reader.ReadToEnd();
            //}

            Image img = Image.FromStream(stream);
}
Image img = Image.FromStream(stream);报“Stream.Length”引发了“System.NotSupportedException”类型的异常  原因是stream不是有效的image,可将回调的结果输出查看是否正确
////获取响应内容
            //using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            //{
            //    strResult = reader.ReadToEnd();
            //}

检查result准确。

 生成小程序码 (errcode: 41030) invalid page hint
此方法生成二维码必须是已经发布的小程序页面,否则无法正常获取小程序码
posted @ 2020-03-25 15:49  碎碎念岁岁恋  阅读(2826)  评论(0编辑  收藏  举报