首页 新闻 搜索 专区 学院

wp8在http请求的时候遇到the remote server returned an error:notfound

0
悬赏园豆:10 [待解决问题]

这个异常在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(); }); 
        }
      //====================获取验证码=======================
Willim的主页 Willim | 初学一级 | 园豆:194
提问于:2014-07-28 23:58
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册