日期:2014-05-17  浏览次数:21039 次

c#从网络读取验证码时出错
我本来想从网络上读取一个验证码显示在winform程序的一个picbox中 可是
/// 获取验证码方法 
        /// </summary> 
        public static Bitmap LoadImg(string ImageUrl)
        {
            try
            {
                HttpWebRequest wrq = (HttpWebRequest)WebRequest.Create(ImageUrl);//请求的URL 
                wrq.Method = "GET";
                wrq.Timeout = 5000;
                wrq.ContentType = "application/x-www-form-urlencoded";
                //获取返回资源 
                HttpWebResponse response = (HttpWebResponse)wrq.GetResponse();
                //获取流 
                Bitmap bt = Bitmap.FromStream(response.GetResponseStream()) as Bitmap;
                return bt;
            }
            catch
            {
                return null;
            }

        }

用这个代码是会出现错误
defaultTransparentColor 无法取消对表达式的引用。指针无效。 System.Drawing.Color
最终返回的是NULL 求大神指教

------解决方案--------------------
设置断点看下获取到的是什么类型的
------解决方案--------------------
楼主何必那么费劲....



pictureBox1.Load("http://captcha.qq.com/getimage?uin=88552244&aid=549000912&0.5529732842087849");



试试就知道了..
------解决方案--------------------
我试过你的代码没问题,是不是你获得的是Post类型的  不是Get