C#-Wp8 http请求的时候遇到the remote server returned an error:notfound
这个异常在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"; //请求方式是GET
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(); });
}
//====================获取验证码=======================
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
手机移动端和pc机移动端是不同的两个,你URL换个手机能上的估计就好了