这个异常在wifi环境下从未出现,但是在2g网络中频繁出现,请问是什么原因,有可能是超时吗,还是请求的是https的原因?
string code_url = "https://mp.weixin.qq.com/cgi-bin/verifycode?username=" + that.acc.Text + "&r=" + (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000; //===================获取验证码======================= public void getVCode(string code_uri) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(code_uri); webRequest.Accept = "image/webp,*/*;q=0.8"; if (loginInfo.LoginCookie != null) webRequest.CookieContainer = loginInfo.LoginCookie; else webRequest.CookieContainer = cc; //保存cookie webRequest.Method = "GET"; //请求方式是POST webRequest.AllowAutoRedirect = true; webRequest.Headers["Accept-Encoding"] = "xxxx,deflate"; webRequest.Headers["Accept-Language"] = "zh-CN"; webRequest.Headers["Connection"] = "keep-alive"; webRequest.Headers["Referer"] = "https://mp.weixin.qq.com/"; webRequest.Headers["Host"] = "mp.weixin.qq.com"; webRequest.Headers["DNT"] = "1"; webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5"; IAsyncResult CodeResult = (IAsyncResult)webRequest.BeginGetResponse(new AsyncCallback(CodeReady), webRequest); } public void CodeReady(IAsyncResult CodeResult) { string u = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000).ToString(); HttpWebRequest request = CodeResult.AsyncState as HttpWebRequest; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(CodeResult); using (Stream stream = response.GetResponseStream()) { if (!Directory.Exists("VC")) { Directory.CreateDirectory("VC"); } FileStream outStream = new FileStream("VC\\VCode"+u+".jpg", FileMode.Create); Int32 i = 0; //循环inStream,将内容写进outStream while (true) { i = stream.ReadByte(); if (i != -1) { outStream.WriteByte((Byte)i); } else { break; } } //关闭文件 outStream.Close(); } // Deployment.Current.Dispatcher.BeginInvoke(() => { t.Text = text2; }); Deployment.Current.Dispatcher.BeginInvoke(() => { that.vc.Source = new BitmapImage(new Uri("VC\\VCode" + u + ".jpg", UriKind.Relative)); that.showVCode(); }); } //====================获取验证码=======================