继上一篇文章,由于本地限制,等后续整理在一起

来源:互联网 发布:淘宝可以直邮韩国么 编辑:程序博客网 时间:2024/04/29 22:20

参考例子:

 byte[] image = File.ReadAllBytes(Environment.CurrentDirectory + @"\AnswerCode.gif");       var param = new Dictionary<object, object>      {                                                                     {"username","test123"},                                                       {"password","123456"},                                                       {"typeid","3040"},                                                      {"timeout","90"}       };    string _tempcodehtml = "";    _tempcodehtml = httph.PostImage(urlcode, param, image);

Http获取图片,既可以通过链接地址,直接用Image的Location=URL也可以将图片流获取到本地,这样请求可以得到图片的Cookie,以便有些验证码存储在Cookie中,可以模拟验证码。

public Bitmap GetImage(string url, ref CookieContainer cookie, string refer)        {            HttpWebRequest hrq = (HttpWebRequest)WebRequest.Create(url);            hrq.Method = "GET";            try            {                HttpWebResponse hrp = (HttpWebResponse)hrq.GetResponse();                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(hrp.GetResponseStream());                if (cookie == null)                {                    cookie.GetCookies(hrq.RequestUri);                }                hrp.Close();                return bmp;            }            catch (Exception)            {                return null;            }        }
0 0
原创粉丝点击